When you are building a package to submit to CRAN and you need to have namespace calls for any function that is being imported. It is a pain to manually parse through the code looking for all the :: and writing it in the roxygen2 header. This function does that for you.
You can write normally your script with the
namespace calls and in the end run the function and you
can paste the output into the header. (or use it as part of
sinew::makeOxygen
or sinew::makeOxyFile
)
The function is written to work on single files or whole directories,
like a package R
subdirectory.
The output can be set to return the format needed for either an roxygen2
header or the DESCRIPTION
pkg_dir <- file.path(tempdir(),'pkg')
pkg_dir_r <- file.path(pkg_dir, 'R')
usethis::create_package(path = pkg_dir, open = FALSE)
#> ✔ Creating '/tmp/RtmpiFEh89/pkg/'.
#> ✔ Setting active project to "/tmp/RtmpiFEh89/pkg".
#> ✔ Creating 'R/'.
#> ✔ Writing 'DESCRIPTION'.
#> ✔ Writing 'NAMESPACE'.
#> ✔ Setting active project to "<no active project>".
withr::with_dir(pkg_dir, usethis::use_data_raw(open = FALSE))
#> ✔ Setting active project to "/tmp/RtmpiFEh89/pkg".
#> ✔ Creating 'data-raw/'.
#> ✔ Adding "^data-raw$" to '.Rbuildignore'.
#> ✔ Writing 'data-raw/DATASET.R'.
#> ☐ Finish writing the data preparation script in 'data-raw/DATASET.R'.
#> ☐ Use `usethis::use_data()` to add prepared data to package.
withr::with_dir(pkg_dir, usethis::use_mit_license(copyright_holder = "John Doe"))
#> ✔ Adding "MIT + file LICENSE" to 'License'.
#> ✔ Writing 'LICENSE'.
#> ✔ Writing 'LICENSE.md'.
#> ✔ Adding "^LICENSE\\.md$" to '.Rbuildignore'.
withr::with_dir(pkg_dir, usethis::use_roxygen_md())
To write the output directly into the Imports field of the
DESCRIPTION
file, specify path to DESCRIPTION
in desc_loc
Package: pkg
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R: person("First", "Last", , "[email protected]", role =
c("aut", "cre"), comment = c(ORCID = "YOUR-ORCID-ID"))
Description: What the package does (one paragraph).
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Imports: stats,
utils
Setting the parameter cut
to an integer value allows for
control of how many functions to list in a package before concatenating
the importFrom
to an import. This is useful when there are
many functions being used throughout the package from the same library
and it is practically the same as just importing the whole library