benmarwick / rrtools

rrtools: Tools for Writing Reproducible Research in R
Other
673 stars 85 forks source link

use_analysis function and pkg path #2

Closed dakni closed 7 years ago

dakni commented 7 years ago

I ran into this issue because I am testing the "RStudio-free" Version of rrtools.

When calling

rrtools::use_analysis()

I receive this output

* Adding bookdown to Imports
Next: 
 * Write your article/paper/thesis in Rmd file(s) in analysis/paper/
 * Add the citation style libray file (csl) to replace the default in analysis/paper/
 * Add reference details to the references.bib in analysis/paper/
 * For adding captions & cross-referenceing in an Rmd, see https://bookdown.org/yihui/bookdown/ 
 * For adding citations & reference lists in an Rmd, see http://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html 

Besides all files are created as expected. Nice.

However, when calling

rrtools::use_analysis(pkg = "MyPackage")

I receive this error

* Adding bookdown to Imports
Error in file.copy(from = list.files(system.file("templates/word_templates/",  : 
  more 'from' files than 'to' files

Why is it not possible to state the pkgpath explicitly? My current attempts failed (I suspect a problem with

Besides the "bug", I think this is a somewhat important issue because IMO it is not good to rely too much on the automagic of RStudio...in this case its automatic changing of the working directory when creating a package.

My workaround looks like this (ugly, I know...):

use_analysis <- function(pkg = ".", template = 'paper.Rmd') {
  if (pkg != ".") {
    setwd(pkg)
    ugly <- TRUE
    pkg <- "."
  }

...

if (ugly == TRUE) {
    setwd("..")
}

invisible(TRUE)
}
benmarwick commented 7 years ago

Thanks for this suggestion. I did feel it was awkward to be double-clicking to open the RStudio project.

So your comment prompted me to replace devtools::create() with a more custom function: rrtools::use_compendium. This new fn is a wrapper for devtools::create(), but also detects if the user is using RStudio. If they are using RStudio, the fn starts the R project. If the user is not useing RStudio, then, the fn just sets the wd to the package dir, exactly as you suggest above. So I think https://github.com/benmarwick/rrtools/commit/f105bbed30146eec8561a7aed5837fb02ac3496a closes this. Let me know how it works for you.

dakni commented 7 years ago

a nice idea to use the rstudio api. I was not aware of it.

The functions works on my ESS-setup and the notice of the working directory change should be sufficient for the non-RStudio users.

Thanks.

benmarwick commented 7 years ago

Thanks for confirming. Yes, I agree that it's important to make this pkg work nicely for R users who do not use RStudio.