Added insertStructure() and subfunctions - #47
Conversation
cebarboza
left a comment
There was a problem hiding this comment.
I think this makes a minimum viable version. Probably we can just test it right away for the thrombo package.
| ) { | ||
|
|
||
| # Need an existing package to run the function | ||
| if (!file.exists(file.path(path, "DESCRIPTION"))) { |
There was a problem hiding this comment.
Probably for a next iteration we can put a check like some of the functions in usethis that detect if the location provided is at the project/package level.
| } | ||
|
|
||
| # Set up structure at specified project path | ||
| cli::cli_h1("Setting up study package structure") |
There was a problem hiding this comment.
Nice cli structure, is very clean
| dir.create(file.path(path, "inst/concept_sets")) | ||
| # extras/ | ||
| dir.create(file.path(path, "extras")) | ||
| invisible(file.create(file.path(path, "extras/CodeToRun.R"))) |
There was a problem hiding this comment.
For a later iteration probably we can plug the actual file with some empty basic functions.
|
|
||
| usethis::use_testthat() | ||
|
|
||
| if (!dir.exists(file.path(path, "R")) | length(list.files(file.path(path, "R"))) == 0) { |
There was a problem hiding this comment.
I think this check is good. Also valuable if this function is exported and we could run this functions separately. But maybe in insert structure, there could be a check that we have R/objective files before actually running this function so it is more clear if there's an error. But for this iteration I think is good.
| } | ||
|
|
||
| # De-comment to reset testPackage structure before testing again | ||
| # unlink(file.path(test_pkg_path, c("extras", "inst", "tests")), recursive = TRUE, force = TRUE) |
There was a problem hiding this comment.
Is there a reason why so many unlink() functions? I think for this general test we could just delete the whole testPackage folder to make it more agile.
There was a problem hiding this comment.
Yes, the reason was it's a bit tricky to create a package from scratch within the code, because both usethis::create_package() and renv::init() are meant to be used interactively and restart the R session by default, interrupting the execution flow. There are parameters to suppress that behaviour, but then there were problems with installPackageBundle() to use renv. So for the moment, to write tests that could run automatically, the functions assume that a package already exists with its core elements. But I can work more on it in the next iteration
There was a problem hiding this comment.
In the following commit, the test creates a temporary project. Let's see how that works.
|
@laacri Also the Github actions seems to be failing because there's no usethis in the description nor in the renv. I can include it and push the change, also with one |
|
@cebarboza I see, sorry I'm not yet too familiar with Github actions. Then yes you can include that, but I'm not sure about the |
|
@laacri I made some modifications to the temporary project. I modified the insertPackageBundle so renv installs to the project explicitely. Maybe later we can check if it installs correctly only with "." as the default parameter for "path" |
Added code for
insertFunction(...)and the subfunctions:installPackageBundle(...)insertDocs(...)insertStudyFiles(...)insertTests(...)Created test files:
test-insertStructure.Rtests/testthat/testPackageto run the testsFor now all the functions have a "default" behaviour, but parameters can be added in the future to install a different package bundle or customize study files. Also, for now they only impact the structure of the study folder and not the content (i.e. all newly created files are empty).
Closes #30, #31, #32, #33, #34 and #21.