MilesMcBain / tflow

An opinionated lightweight template for smooth targets flows.
Other
90 stars 9 forks source link

use_rmd error and some smaller formatting things #1

Closed shirdekel closed 3 years ago

shirdekel commented 3 years ago

Hey Miles, thanks for making this; tflow might be what finally gets me over the line to try out targets in an actual project. Just had some issues with use_rmd, which I'm some have easy fixes.

  1. When I call use_rmd("analysis") I get the following error:
✔ Writing 'doc/analysis.Rmd'
Error in eval(parse(text = text, keep.source = FALSE), envir) : 
  object 'target' not found

I'm not sure how to set up a reprex to make it work with all the usethis calls, but the error seems to come from this glue call in rmd_target:

target_name <- "analysis"
report_dir <- "doc"
glue::glue(
    "Add this target to your tar_plan():\n",
    "\n",
    "tar_render({target}, \"{file.path(report_dir, paste(target_name, '.Rmd', sep = '.'))}\")\n"
)
#> Error in eval(parse(text = text, keep.source = FALSE), envir): object 'target' not found

Created on 2021-01-22 by the reprex package (v0.3.0)

Session info devtools::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.0.2 (2020-06-22) #> os macOS Mojave 10.14.6 #> system x86_64, darwin17.0 #> ui X11 #> language (EN) #> collate en_AU.UTF-8 #> ctype en_AU.UTF-8 #> tz Australia/Sydney #> date 2021-01-22 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.0) #> callr 3.5.1 2020-10-13 [1] CRAN (R 4.0.2) #> cli 2.2.0 2020-11-20 [1] CRAN (R 4.0.2) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.0) #> desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.0) #> devtools 2.3.0 2020-04-10 [1] CRAN (R 4.0.0) #> digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.2) #> ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.0) #> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.0) #> fansi 0.4.2 2021-01-15 [1] CRAN (R 4.0.2) #> fs 1.5.0 2020-07-31 [1] CRAN (R 4.0.2) #> glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.2) #> highr 0.8 2019-03-20 [1] CRAN (R 4.0.0) #> htmltools 0.5.0 2020-06-16 [1] CRAN (R 4.0.2) #> knitr 1.30 2020-09-22 [1] CRAN (R 4.0.2) #> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.0) #> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.0.2) #> memoise 1.1.0 2017-04-21 [1] CRAN (R 4.0.0) #> pkgbuild 1.2.0 2020-12-15 [1] CRAN (R 4.0.2) #> pkgload 1.1.0 2020-05-29 [1] CRAN (R 4.0.0) #> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.0) #> processx 3.4.5 2020-11-30 [1] CRAN (R 4.0.2) #> ps 1.5.0 2020-12-05 [1] CRAN (R 4.0.2) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.0.0) #> R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.2) #> remotes 2.2.0 2020-07-21 [1] CRAN (R 4.0.2) #> rlang 0.4.10 2020-12-30 [1] CRAN (R 4.0.2) #> rmarkdown 2.5 2020-10-21 [1] CRAN (R 4.0.2) #> rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.0.2) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.0) #> stringi 1.5.3 2020-09-09 [1] CRAN (R 4.0.2) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.0) #> testthat 3.0.1 2020-12-17 [1] CRAN (R 4.0.2) #> usethis 2.0.0 2020-12-10 [1] CRAN (R 4.0.2) #> withr 2.4.0 2021-01-16 [1] CRAN (R 4.0.2) #> xfun 0.19 2020-10-30 [1] CRAN (R 4.0.2) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.0) #> #> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library

I'd be happy to submit a pull request, but I'm unsure what {target} is meant to be. In your README it's simply "report" and in dflow:::rmd_target you made it "target_name". So maybe just remove the curly brackets?

  1. Separately, the paste call has both '.Rmd' and sep = '.', which ends up like this for me:

    target_name <- "analysis" report_dir <- "doc" file.path(report_dir, paste(target_name, '.Rmd', sep = '.'))

    > [1] "doc/analysis..Rmd"

Created on 2021-01-22 by the reprex package (v0.3.0)

  1. Also, rmd_target(file_path) could just be rmd_target(target_name) if rmd_target already adds in the file path and extension, right? Otherwise it ends up like this:

    target_name <- "analysis" report_dir <- "doc" target_file <- paste0(target_name, ".Rmd") file_path <- file.path(report_dir, target_file) file.path(report_dir, paste(file_path, ".Rmd", sep = "."))

    > [1] "doc/doc/analysis.Rmd..Rmd"

Created on 2021-01-22 by the reprex package (v0.3.0)

Let me know if you'd like a pull request and/or if my assumptions are off.

MilesMcBain commented 3 years ago

Oh dear I really made a mess of this one somehow. I have no idea how the test I ran yesterday worked, probably some stale state I guess.

Thanks so much for the report, no PR necessary, I'll be using this one myself frequently.

MilesMcBain commented 3 years ago

I think I have fixed this now?

shirdekel commented 3 years ago

Thanks! It works when analysis.Rmd doesn't exist, but my third point is still an issue. That is, when analysis.Rmd exists, then I get the following:

doc/analysis.Rmd already exists and was not overwritten.
Add this target to your tar_plan():

tar_render(doc/analysis.Rmd, "doc/doc/analysis.Rmd.Rmd")

Perhaps just change file_path here to target_name?

MilesMcBain commented 3 years ago

Ohhh sorry my bad, I misunderstood the 3rd item!

MilesMcBain commented 3 years ago

That was the fix thanks. Feel free to add yourself as a ctb in the DESCRIPTION if you like 👍

shirdekel commented 3 years ago

Yep, works now! I'll send a pull request shortly, thank you 😄