admin

[This article was first published on Statistical Science & Related Matters on Less Likely, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
options("RStata.StataVersion" = 17.0)
options("RStata.StataEcho" = 1)
knitr::opts_knit$set(
  progress = F,
  verbose = F
)
statapath <- ("/Applications/Stata/statabe.app/Contents/MacOS/statabe")
lang <- list("r", "stata", "python", "julia", "bash", "css", "html", "js", "sql", "sas", "fortran", "c++")
knitr::knit_engines$set(lang[])

knitr::opts_chunk$set(
  comment = "#>",
  tidy = FALSE,
  tidy.opts = list(width.cutoff = 60),
  collapse = TRUE,
  prompt = FALSE,
  dev = c("CairoPNG", "pdf"),
  dev.args = list(dev = list(compression = "lzw")),
  highlight = TRUE,
  numberLines = TRUE,
  warning = FALSE,
  verbose = FALSE,
  message = FALSE,
  fig.align = "center",
  class.output = c("hljs", "highlightjs", "figure"),
  dev.args = list(bg = "transparent"),
  engine.path = list(
    (stata <- statapath),
    (python <- "~/Library/r-miniconda-arm64/envs/r-reticulate/bin/python3.8")
  ),
  RETICULATE_PYTHON <- "~/Library/r-miniconda-arm64/envs/r-reticulate/bin/python3.8",
  cache = FALSE,
  purl = FALSE,
  cache.lazy = FALSE,
  fig.retina = 2
)
reticulate::use_python("~/Library/r-miniconda-arm64/envs/r-reticulate/bin/python3.8")
rmarkdown::find_pandoc()
## $version
## [1] '3.6.4'
## 
## $dir
## [1] "/opt/homebrew/bin"
res_names <- c(
  "Term", "Estimate", "Std.Error",
  "Statistic", "df", "P.value"
)
CMS.registerEditorComponent({
  // Internal id of the component
  id: "collapsible-note",
  // Visible label
  label: "Collapsible Note",
  // Fields the user need to fill out when adding an instance of the component
  fields: [
    {
      name: 'summary',
      label: 'Summary',
      widget: 'string'
    },
    {
      name: 'contents',
      label: 'Contents',
      widget: 'markdown'
    }
  ],
  // Regex pattern used to search for instances of this block in the markdown document.
  // Patterns are run in a multiline environment (against the entire markdown document),
  // and so generally should make use of the multiline flag (`m`). If you need to capture
  // newlines in your capturing groups, you can either use something like
  // `([\S\s]*)`, or you can additionally enable the "dot all" flag (`s`),
  // which will cause `(.*)` to match newlines as well.
  //
  // Additionally, it's recommended that you use non-greedy capturing groups (e.g.
  // `(.*?)` vs `(.*)`), especially if matching against newline characters.
  pattern: /^<details>$\s*?<summary>(.*?)<\/summary>\n\n(.*?)\n^<\/details>$/ms,
  // Given a RegExp Match object
  // (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match#return_value),
  // return an object with one property for each field defined in `fields`.
  //
  // This is used to populate the custom widget in the markdown editor in the CMS.
  fromBlock: function(match) {
    return {
      summary: match[1],
      contents: match[2]
    };
  },
  // Given an object with one property for each field defined in `fields`,
  // return the string you wish to be inserted into your markdown.
  //
  // This is used to serialize the data from the custom widget to the
  // markdown document
  toBlock: function(data) {
    return `
<details>
  <summary>${data.summary}</summary>

  ${data.contents}

</details>
`;
  },
  // Preview output for this component. Can either be a string or a React component
  // (component gives better render performance)
  toPreview: function(data) {
    return `
<details>
  <summary>${data.summary}</summary>

  ${data.contents}

</details>
`;
  }
});

To leave a comment for the author, please follow the link and comment on their blog: Statistical Science & Related Matters on Less Likely.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)