0

I am roxygenizing a package I am making in R.

The script is

#' HandyTools
#'
#' Check if required packages are installed or not and installs them if not
#' @param packageList - a list containing the required package names
#'
#' @examples
#' checkPackagesLibrary(c("lme4","epitools","roxygen2"))
#'
#' @export
library(devtools)
checkPackagesLibrary <- function(packagesList){
  new.packages <- packagesList[!(packagesList %in% installed.packages(lib.loc="/data/legacy/user/R_Packages")[,"Package"])]
  if(length(new.packages))
    install.packages(new.packages, lib = "/data/legacy/user/R_Packages")
  else
    print("Required packages are already installed")
}

While build and reload in RStudio, the error is:

==> devtools::document(roclets=c('rd', 'collate', 'namespace', 'vignette'))

Updating HandyTools documentation
Loading HandyTools
Error: Missing name at code.R:14
In addition: Warning message:
In setup_ns_exports(pkg, export_all) :
  Objects listed as exports, but not present in namespace: c
Execution halted

Exited with status 1.

Error is at line 14, which is

library(devtools)

If I comment this line, the error disappears.

j1897
  • 1,507
  • 5
  • 21
  • 41

1 Answers1

3

Rookie error: you are not supposed to have library()... calls in scripts in your packages.

Use DESCRIPTION and NAMESPACE instead, preferably via Imports: and importFrom() statements.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • 1
    For rookies: rather than use library(package), in packages it is considered better to fully specify every use of a package with the :: such as data.table::uniqueN – PeterVermont Mar 19 '17 at 02:24
  • 1
    @PeterVermont what is standard practice when we call upon functions from another package *many* times. It really dirties up the code to write `dplyr::` a hundred times. I specify the packages it requires with `Imports:`. It seems SOP to still include `package::` at the beginning, but I really don't want to do that. – Mark White Jul 11 '17 at 19:15