automated data analysis workflows
I have the following code in my packagename.R
file in the packagename
folder.
I know I am going to use certain functions from other packages routinely, so I want to import them once instead of typing them out all over the place. I thought I should be able to do that with the above approach, but it's not working in my RStudio.
#' packagename: Package containing tools support project work.
#'
#' This package provides a central repository for methods to facilitate
#' project work
#' @importFrom dplyr bind_rows mutate filter group_by ungroup
#' @importFrom purrr pluck map map_chr map_dbl
#' @importFrom lubridate ymd_hms
#' @importFrom odbc odbc
#' @importFrom DBI dbConnect dbDisconnect
#' @importFrom stringr str_detect str_replace_all
#' @docType package
#' @name packagename
NULL
In another file topic.R
I have:
do_thing <- function(x) str_replace_all(x, " ", "_"))
When I call do_thing
it tells me:
Error in str_replace_all(x, " ", "_") :
could not find function "str_replace_all"
Is there something more I need to add, or perhaps should I do something differently?
Based on the comments to the question, I needed to atleast regenerate my NAMESPACE
, which apparently was generated manually (since I started the project using the RStudio GUI), so roxygen
wouldn't update it. I am interested in how I can do this from the UI as well.
This is what my build menu looks like:
My NAMESPACE
file includes these imports but my test script still fails when trying to run the functions. Is this not possible as C. Braun suggests?
@importFrom
specifically at the top of every function that uses them. But why don't you just load the whole library if you are routinely using those functions across your package. – BedraggleNAMESPACE
just hasexportPattern("^[[:alpha:]]+")
. Maybe I have to rundocument()
and not just rely onctrl-shift-b
. Is there any way to do that from RStudio outside of the console? – Bikiniroxygen
does not append to / overwrite manually maintained NAMESPACE files – LaoagNAMESPACE
file. That's not ideal, but after deleting it and runningdocument()
, myNAMESPACE
is looking right. Thanks! I'm will to accept that as an answer. – BikiniNAMESPACE
from the RStudio GUI. – Bikinictrl-shift-d
doesn't regenerate theNAMESPACE
for you? – BedraggleBuild -> Document
which calls this command:devtools::document(roclets=c('rd', 'collate', 'namespace', 'vignette'))
– BedraggleNAMESPACE
. – Bikinidevtools
installed and can run thedocument
function directly? – BedraggleNAMESPACE
, which I'm really surprised about since that isn't the behavior exhibited by a package I developed with Emacs/ESS on R 3.3.3 (which I wouldn't have thought would matter). – Bikinibuild > Configure Build Tools > Configure
and then check the boxes for letting roxygen build vignettes (I have all of them checked for my pacakges/ builds). These are unchecked by default when starting a package. – GeneratorImports:
section there needs to list all the packages that you want to import from. Roxygen does not offer any means to do this automatically – Laoag