benmarwick / rrtools

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

Multiple path_to_rmd guessed incorrectly in Dockerfile & .travis.yml when paper_files/ dir exists in paper/ #99

Closed annakrystalli closed 4 years ago

annakrystalli commented 4 years ago

Please wait for some discussion of your report before making a Pull Request.

Describe the bug

If one has rendered the paper manually and a paper_files/ folder has been created within paper/, this confuses the guessing of the path to paper.Rmd erroneous paths to be added to the populated Dockerfile & .travis.yml templates .

To Reproduce

dir.create("analysis/paper/paper_files", recursive = T)
dir_list   <- list.dirs()
paper_dir  <- dir_list[grep(pattern = "/paper", dir_list)]
paper_dir
#> [1] "./analysis/paper"             "./analysis/paper/paper_files"
rmd_path   <- regmatches(paper_dir, regexpr("analysis|vignettes|inst", paper_dir))
rmd_path
#> [1] "analysis" "analysis"
rmd_path <-  file.path(rmd_path, "paper/paper.Rmd")
rmd_path
#> [1] "analysis/paper/paper.Rmd" "analysis/paper/paper.Rmd"

Created on 2019-09-11 by the reprex package (v0.3.0)

In practice, this results in the Dockerfile resulting from use_dockerfile() containing this incorrect markdown::render() command:

  && R -e "rmarkdown::render('/rrcompendiumRSE19/analysis/paper/paper.Rmd,analysis/paper/paper.Rm')"

Same problem with the .travis.yml file from rrtools::use_travis()

Expected behavior

I think this can be fixed by adding a $ to the end of the pattern in grep(). eg:


dir.create("analysis/paper/paper_files", recursive = T)
dir_list   <- list.dirs()
paper_dir  <- dir_list[grep(pattern = "/paper$", dir_list)]
paper_dir
#> [1] "./analysis/paper"
rmd_path   <- regmatches(paper_dir, regexpr("analysis|vignettes|inst", paper_dir))
rmd_path
#> [1] "analysis"
rmd_path <-  file.path(rmd_path, "paper/paper.Rmd")
rmd_path
#> [1] "analysis/paper/paper.Rmd"

returns only a single file path

Created on 2019-09-11 by the reprex package (v0.3.0)

benmarwick commented 4 years ago

Thanks! I think I can follow what you're describing here, I'll take a closer look!