usethis::use_template() and directories

As TJ Mahr pointed out to me recently, use_template() could be handy for solving use_drake() · Issue #773 · ropensci/drake · GitHub. However, use_template() appears to focus on individual template files, whereas use_drake() · Issue #773 · ropensci/drake · GitHub needs a slightly more complicated directory structure.

_drake.R
make.R
R/
├── packages.R
├── functions.R
└── plan.R

The R/ directory appears challenging.

dir.create("lib")
.libPaths("lib")
remotes::install_github(
  "ropensci/drake",
  ref = "372ceeea974d22aef24395f04155ca512c078792",
  lib = "lib",
  quiet = TRUE
)
usethis::create_project(".")
#> ✔ Setting active project to '/tmp/RtmpAugJFV/reprex24d36b004e55'
#> ✔ Creating 'R/'
#> ✔ Writing a sentinel file '.here'
#> ● Build robust paths within your project via `here::here()`
#> ● Learn more at https://here.r-lib.org
system.file(
  file.path("templates", "usedrake", "R"),
  package = "drake",
  mustWork = TRUE
)
#> [1] "/tmp/RtmpAugJFV/reprex24d36b004e55/lib/drake/templates/usedrake/R"
usethis::use_template(
  file.path("usedrake", "R"),
  save_as = "R",
  package = "drake"
)
#> Error in if (is.null(template) || template == "") {: missing value where TRUE/FALSE needed

Created on 2019-03-13 by the reprex package (v0.2.1)

Can the usethis API create an R/ folder at the project root while invoking the same checks and safeguards as use_template()? If not, what should I keep in mind as I implement a safe manual workaround?

If you post to GitHub, would you mind including the issue here as well? (I realize your GH question is more specific, but I think it's still relevant). That way the discussion is less likely to be fragmented/any resolution in the package can be more easily found by someone who comes across the question here. Thanks.

Good idea @mara, thanks for including the link. If I open more GitHub issues on this topic, I will mention them in this thread.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.