Interactive workflow
jacobbien opened this issue · 3 comments
Currently if one pressed "Run all" in RStudio, one gets an error because usethis
expects itself to be called from a package directory, but create-mypkg.Rmd
lives in mypkg-project
. One gets the error in the usethis::create_package()
call and also in calls to usethis::use_package()
.
It'd be nice if "Run all" would work in Rstudio. Or if there's a simple alternative, e.g., a function like litr::load_all("create-mypkg.Rmd")
that would load the current code into the console. At this point, I can think of two approaches for implementing litr::load_all()
:
- It calls
litr::render()
and thendevtools::load_all("mypkg/")
. I don't love this approach becauselitr::render()
can be slow and I'm hoping for something more immediate. - Use mockery to replace all
usethis
functions with stubs that don't do anything. I believe this should work but it might have some side-effects that I'm not thinking of.
It's also worth looking into what happens when one clicks "Run all" to see if one can do something like approach 2 before running all blocks.
Two workflow focused changes that don't directly involve RStudio:
litr::load_all("create-mypkg.Rmd")
should create the package without creating a .html file (i.e., it doesn't run any of the code chunks, it only runs the hooks that create the R package. Then it calls devtools::load_all("mypkg/")
.
Another convenient function geared towards an easier workflow:
litr::render("create-mypkg.Rmd", test = FALSE, eval = FALSE)
The test=FALSE
would mean that any code chunk that has test_that
in it is not run. The eval=FALSE
would mean that all code chunks are not run. This allows user to, for example, make changes to the text without rerunning everything.
An important modification of the above plan is that code chunks that call usethis
commands will still need to be run for the package to be properly created. For example, usethis::create_package()
and usethis::use_package()
will need to be run.
This issue is closed by #38, which implements litr::load_all()
and minimal_eval=TRUE
as a possible setting for litr::render()
and to output formats. The "Run All" issue described at the start of the issue is not directly addressed, but the need for it is, I believe, reduced. We can open a new issue about "Run All" if it still seems needed.