Error while importing mice functions in R package -
i include mice::mice function in package perform imputation on data.
i use roxygen list imports
#' @param data dataset used imputation #' @importfrom dplyr select_ #' @importfrom mice mice complete #' @return list #' @export #' impute_data <- function(data, vars, seed) { data_used <- select_(data,vars) mice_data <- complete(mice(data_used, seed = seed)) return(mice_data) }
this function works fine when test code, when build package , try use it, following error
error in check.method(setup, data) : following functions not found: mice.impute.pmm,mice.impute.pmm, mice.impute.pmm, mice.impute.pmm, mice.impute.pmm
i tried add imports functions mentioned in error had no effect whatsoever on outcome.
what missing? i've never found such problem.
you forgetting handle description file! handle impute_data.r.
your question quite similar to: what roxygen should put when use function of package in function
i gave answer there (please search similar questions before posting question). case:
first, being aware of your
sessioninfo() getwd() # r's working directory .libpaths() # r's library location
step0 download , install necessary packages:
library(roxygen2) library(devtools) library(digest)
step1 put related ".r" files (yourfunction1.r, yourfunction2.r, yourfunction3.r, impute_data.r) r's working directory.
step2 create package skeleton in r's working directory: sure there no folder named "yourpackage" in r's working directory before running following command. (from r's console)
package.skeleton(name = "yourpackage", code_files = c("yourfunction1.r", "yourfunction2.r", "yourfunction3.r", "impute_data.r"), path = ".")
after running package.skeleton
, folder yourpackage created in r's working directory.
delete read-and-delete-me
file windows explorer.
delete "yourpackage-package.rd" file in yourr'sworkingdirectory\yourpackage\man folder
(do not delete "yourpackage.rd" file in yourr'sworkingdirectory\yourpackage\man folder!)
step3 @ end of preamble of ".r" file (impute_data.r), put following (if had not done in step1):
#' @importfrom mice mice #' @importfrom mice complete #' @export impute_data <- function(...) {...
step4 in description
file of package, in imports
part, add:
imports: mice(>= versionnumber)
where versionnumber version number of mice package using. can find version number right-click function (from yourpackage) in object browser of revolutionrenterprise; , going bottom of resultant .html file. there, version number of package shown.
in step2, package.skeleton automatically produced namespace file content is:
exportpattern("^[[:alpha:]]+")
do not handle namespace file manually.
step5 roxygenize package wanna create ("yourpackage")
library(roxygen2) roxygenize("yourpackage")
upon roxygenization, content of namespace file of yourpackage automatically converted exportpattern("^[[:alpha:]]+")
# generated roxygen2: not edit hand export(impute_data) importfrom(mice,mice) importfrom(mice,complete)
step6 build package:
(first, delete "src-i386" , "src-x64" folders (if any) in yourr'sworkingdirectoryfolder\yourpackage folder windows explorer)
(be sure again there no "yourpackage-package.rd" file in yourr'sworkingdirectory\yourpackage\man folder. if there is, delete before building)
build("yourpackage")
step7 install package:
install("yourpackage")
step8 check going loading package , running function in package.
library(yourpackage) impute_data(a,b,1235) # "impute_data" function in package "yourpackage"
step9 check package loadable cran (comprehensive r archieve network) (if wanna share package):
(first, delete "src-i386" , "src-x64" folders (if any) in yourr'sworkingdirectoryfolder\yourpackage folder windows explorer)
(be sure again there no "yourpackage-package.rd" file in yourr'sworkingdirectory\yourpackage\man folder. if there is, delete before checking)
from dos command prompt:
start – cmd - enter. pass r's working directory (your r's working directory known via getwd()) , cran check:
cd c:\users\user\documents\revolution r cmd check yourpackage
from r's console:
devtools::check("c:/users/user/documents/revolution/yourpackage")