I am new to R package development and stack overflow, but I could not find this information anywhere.
I am trying to load R-packet mice without polluting my namespace. I tried to import only those functions that I use, but this did not work. Therefore, I agree to download the entire package in one specific environment as follows:
e <- new.env() load_package_into_environment(e, package = "mice") eval(mice(data, m = m, maxit = max.iter, printFlag = F), envir = e)
However, I could not find the actual function to replace the placeholder "load_package_into_environment". What function, if any, will accomplish this?
EDIT: Here are the files I'm working with and the problem I have to provide in more detail.
File: DESCRIPTION
Package: bug.example2 Title: Example of Package Loading Bug Version: 0.0.0.9000 Authors@R : person("R", "Woodbridge", email = " example@gmail.com ", role = c("aut", "cre")) Description: Creates a wrapper function for mice::mice function. Depends: R (>= 3.2.3), data.table (>= 1.9.6) License: LazyData: true Imports: mice RoxygenNote: 5.0.1
File: NAMSPACE (automatically generated by roxygen)
import(data.table) importFrom(mice,mice) importFrom(mice,mice.impute.logreg) importFrom(mice,mice.impute.pmm) importFrom(mice,mice.impute.polr) importFrom(mice,mice.impute.polyreg)
File: impute.R (uses the function of the mice from the mouse package)
File: test-impute.R (uses a test package to test the impute function)
context("Impute missing values") test_that("Output format is a list of lenght m and each element is a data.table",{ #Set up data set.seed(200) data <- iris data$Species[runif(nrow(data)) < .1] <- NA data$Sepal.Width[runif(nrow(data)) < .2] <- NA setDT(data) #Create imputed data M <- 5 impute.output <- impute(data, m = M) #Test output format expect_is(impute.output, "list") expect_equal(length(impute.output), M) lapply(impute.output,expect_is, "data.table") })
Error output from testthat
1. Error: Output format is a list of lenght m and each element is a data.table - The following functions were not found: mice.impute.pmm, mice.impute.polyreg 1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls, message = function(c) invokeRestart("muffleMessage")) 2: eval(code, new_test_environment) 3: eval(expr, envir, enclos) 4: impute(data, m = M) at test-impute.R:12 5: mice(data, m = m, maxit = max.iter, printFlag = F) at C:\repos\bug.example2/R/impute.R:11 6: check.method(setup, data) 7: stop(paste("The following functions were not found:", paste(fullNames[notFound], collapse = ", ")))