Scrape R
script to create import and importFrom calls for
roxygen2, namespace or description files
make_import( script, cut = NULL, print = TRUE, format = "oxygen", desc_loc = NULL )
script | character, connection to pass to readLines, can be file path, directory path, url path |
---|---|
cut | integer, number of functions to write as importFrom until switches to import, Default: NULL |
boolean, print output to console, Default: TRUE |
|
format | character, the output format must be in c('oxygen','description','import'), Default: 'oxygen' |
desc_loc | character, path to DESCRIPTION file, if not NULL then the Imports fields in the DESCRIPTION file, Default: NULL |
# copy dummy package to tempdir file.copy(system.file('pkg',package = 'sinew'),tempdir(),recursive = TRUE)#> [1] TRUEpkg_dir <- file.path(tempdir(),'pkg') pkg_dir_R <- file.path(pkg_dir,'R') pkg_dir_DESC <- file.path(pkg_dir,'DESCRIPTION') # update namespaces in package functions pretty_namespace(pkg_dir_R, overwrite = TRUE)#> #> functions changed in '/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T//RtmpsuvloD/pkg/R/yy.R': #> #> ✔: found, ✖: not found, (): instances, ☒: user intervention #> #> ✔ utils::head (1) #> ✔ stats::runif (1) #> #> #> functions changed in '/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T//RtmpsuvloD/pkg/R/zz.R': #> #> ✔: found, ✖: not found, (): instances, ☒: user intervention #> #> ✔ utils::head (1) #> ✔ stats::runif (1) #># update imports/importsFrom for roxygen2 tags make_import(pkg_dir_R,format = 'oxygen')#> #> /var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T//RtmpsuvloD/pkg/R/yy.R #> #' @importFrom utils head #> #' @importFrom stats runif #> #> /var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T//RtmpsuvloD/pkg/R/zz.R #> #' @importFrom utils head #> #' @importFrom stats runif# update Imports for DESCRIPTION file output to console make_import(pkg_dir_R,format = 'description')#> Imports: #> stats, #> utils# update Imports for DESCRIPTION file overwrite file make_import(pkg_dir_R,format = 'description', desc_loc = pkg_dir)#> Imports: #> stats, #> utils#> Package: pkg #> Title: What the Package Does (One Line, Title Case) #> Version: 0.0.0.9000 #> Authors@R: person(given = "First", family = "Last", role = c("aut", #> "cre"), email = "first.last@example.com", comment = c(ORCID = #> "YOUR-ORCID-ID")) #> Description: What the package does (one paragraph). #> License: MIT + file LICENSE #> Encoding: UTF-8 #> LazyData: true #> Roxygen: list(markdown = TRUE) #> RoxygenNote: 6.1.1 #> Imports: stats, utils