Coder Social home page Coder Social logo

Do I need to configure `poly-r-rmarkdown-template-dirs` manually, even for templates included with installed R packages (e.g. tufte)? about poly-r HOT 5 CLOSED

polymode avatar polymode commented on July 22, 2024
Do I need to configure `poly-r-rmarkdown-template-dirs` manually, even for templates included with installed R packages (e.g. tufte)?

from poly-r.

Comments (5)

vspinu avatar vspinu commented on July 22, 2024

It's automatic. All the ones installed should be shown in the template. For example, install the package tufte and a submenu in RMarkdown > Template > Tufte will appear. See the doc string of poly-r-rmarkdown-create-from-template for a few examples of common packages that provide the templates. Let me know if you find more.

from poly-r.

vspinu avatar vspinu commented on July 22, 2024

There might be R/ESS/poly-R version mismatch. What versions do you use? You need fairly recent poly-R for this. The relevant R code is here.

It boils down to the following:

list_templates <- 
  function(user_dirs) {
    user_dirs <- c(user_dirs, unlist(lapply(user_dirs, list.dirs, recursive = FALSE)))
    list_from_dir <- function(dir, pkg = NULL) {
      pkg_name <- if(is.null(pkg)) 'USER' else pkg
      if (dir.exists(dir)) {
        dirs <- list.dirs(dir, recursive = FALSE)
        for (d in dirs) {
          yaml_file <- file.path(d, 'template.yaml')
          if (file.exists(yaml_file)) {
            yaml <- rmarkdown:::yaml_load_file_utf8(yaml_file)
            if (is.null(desc <- yaml$description)) desc <- 'nil'
            cat(sprintf('(\"%s\" \"%s\" \"%s\" \"%s\")\n', pkg_name, d, yaml$name, desc))
          }
        }
      }
    }
    cat('(\n')
    for (user_dir in user_dirs) {
      files <- list.files(user_dir,  '\\.[Rr]md$', full.names = TRUE)
      for (f in files) {
        name <- sub('\\.[^.]+$','', basename(f))
        cat(sprintf('(\"USER\" \"%s\" \"%s\")\n', f, name))
      }
      list_from_dir(user_dir)
    }
    packages <- sort(unlist(lapply(.libPaths(), dir)))
    for (pkg in packages) {
      template_folder <- system.file('rmarkdown', 'templates', package = pkg)
      list_from_dir(template_folder, pkg)
    }
    cat(')\n')
  }

list_templates(c())

and should produce something along:


(
("rmarkdown" "/home/vspinu/.lib/3.6.0/rmarkdown/rmarkdown/templates/github_document" "GitHub Document (Markdown)" "Template for documents to be published as GitHub Flavored Markdown.
")
("rmarkdown" "/home/vspinu/.lib/3.6.0/rmarkdown/rmarkdown/templates/html_vignette" "Package Vignette (HTML)" "Template for package vignettes. This customises the basic HTML output to take up as little space as possible.
")
("tufte" "/home/vspinu/.lib/3.6.0/tufte/rmarkdown/templates/tufte_ctex" "Tufte Handout (HTML or PDF in Chinese)" "A Chinese template for creating a handout according to the style of Edward R. Tufte and Richard Feynman.
")
("tufte" "/home/vspinu/.lib/3.6.0/tufte/rmarkdown/templates/tufte_html" "Tufte Handout (HTML or PDF)" "Template for creating a handout according to the style of Edward R. Tufte and Richard Feynman.
")
)

from poly-r.

jerlev avatar jerlev commented on July 22, 2024

Got it. I found an issue with the call to rmarkdown:::yaml_load_file_utf8. In recent versions of rmarkdown this function has been renamed yaml_load_file (rstudio/rmarkdown@8e62228). With that fixed in my local copy of poly-r.el, and after running byte-compile-file, the items are found, and the menu now looks as expected.

from poly-r.

vspinu avatar vspinu commented on July 22, 2024

Thanks for identifying the issue. Should be fixed now.

from poly-r.

antonellosalis avatar antonellosalis commented on July 22, 2024

I have the same issue..

from poly-r.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.