I am parsing argument in a rscript (merge_em.r) below. Let's say I run the code below using commandline Rscript merge_em.r dataframe1, dataframe2 which gives me this error: Error in setwd(working.dir) : character argument expected. I want to keep working directory argument optional. How do I do it?
library("argparse")
merge_em <- function (x, y, working.dir){
mergedfile <- merge (x, y, by = intersect(names(x), names(y)))
if (missing(working.dir)) {
print ("Working directory not specified! Will use present working directory.")
working.dir <- as.character(file.path(getwd()))
} else {
working.dir <- working.dir
}
setwd(working.dir)
write.table (mergedfile, "merged.txt",
col.names = FALSE,
row.names = FALSE,
sep = "\t",
quote = FALSE
)
}
main <- function() {
# breaks if you set warn = 2
options(error = traceback,
warn = 1)
parser <- ArgumentParser(prog = "merge_em.r",
description = "Merge dataframes")
parser <- ArgumentParser()
parser$add_argument("x")
parser$add_argument("y")
parser$add_argument(
"--working_dir",
dest = "working.dir",
type = "character",
metavar = "DIR",
required = FALSE,
help = "Working directory where files are present"
)
args <- parser$parse_args()
working.dir <- args$working.dir
x <- args$x
if (!R.utils::isAbsolutePath(x))
x <- file.path(working.dir, x)
y <- args$y
if (!R.utils::isAbsolutePath(y))
y <- file.path(working.dir, y)
tryCatch(
merge_em (x, y, working.dir)
,
finally = setwd(working.dir)
)
}
main()
You could exchange the missing() conditional to this:
if (working.dir=="") {
print ("Working directory not specified! Will use present working directory.")
working.dir <- as.character(file.path(getwd()))
} else {
print ("Working directory is specified!")
working.dir <- working.dir
}
And change the argument for working_dir to (default=""):
parser$add_argument(
"--working_dir",
dest = "working.dir",
type = "character",
metavar = "DIR",
default="",
required = FALSE,
help = "Working directory where files are present"
)
And change the tryCatch to:
tryCatch(merge_em(x, y, working.dir), finally = print("Fin"))
Why are you using setwd() io the finally part? If the argument is not given, there is nothing to set or?
Like that you can call the script like this, for example:
Rscript merge_em.r data_frame1, data_frame2
Or with a directory:
Rscript merge_em.r data_frame1, data_frame2, --working_dir "path_to_folder"
Full code:
library(argparse)
merge_em <- function (x, y, working.dir){
mergedfile <- merge (x, y, by = intersect(names(x), names(y)))
if (working.dir=="") {
print ("Working directory not specified! Will use present working directory.")
working.dir <- as.character(file.path(getwd()))
} else {
print ("Working directory is specified!")
working.dir <- working.dir
}
setwd(working.dir)
write.csv(x = mergedfile, file = "merged.txt",
row.names = FALSE,
quote = FALSE
)
}
main <- function() {
# breaks if you set warn = 2
options(error = traceback,
warn = 1)
parser <- ArgumentParser(prog = "merge_em.r",
description = "Merge dataframes")
parser <- ArgumentParser()
parser$add_argument("x")
parser$add_argument("y")
parser$add_argument(
"--working_dir",
dest = "working.dir",
type = "character",
metavar = "DIR",
default="",
required = FALSE,
help = "Working directory where files are present"
)
args <- parser$parse_args()
working.dir <- args$working.dir
x <- args$x
if (!R.utils::isAbsolutePath(x))
x <- file.path(working.dir, x)
y <- args$y
if (!R.utils::isAbsolutePath(y))
y <- file.path(working.dir, y)
tryCatch(merge_em(x, y, working.dir), finally = print("Fin"))
}
main()
You can set it as a default and override it when necessary.
merge_em <- function (x, y, working.dir = getwd()){
mergedfile <- merge (x, y, by = intersect(names(x), names(y)))
setwd(working.dir)
write (mergedfile, "merged.txt",
col.names = FALSE,
row.names = FALSE,
sep = "\t",
quote = FALSE
)
}
And override it with some other value:
merger_em(x, y, 'another/path/dir')
I haven't tested this, but default parameters are a standard in many languages.
Also, you can setwd with getwd like: setwd(getwd())
Related
Here is an example of how I "manually" add a HTML dependency to a datatable. This works fine. When I try with attachDependencies, the dependency is not attached.
library(DT)
library(htmltools)
dep <- htmlDependency(
name = "colResize",
version = "1.6.1",
src = normalizePath("colResize"),
script = "jquery.dataTables.colResize.js",
stylesheet = "jquery.dataTables.colResize.css",
all_files = FALSE
)
dat <- iris
datatable(
dat,
options = list(
colResize = list()
)
) %>% attachDependencies(dep, append = TRUE)
Why does this code not work?
I don't think it has anything to do with the way you're using it. The function attachDependencies() adds the object as an attribute, not as a dependency:
function (x, value, append = FALSE)
{
value <- asDependencies(value)
if (append) {
old <- attr(x, "html_dependencies", TRUE)
htmlDependencies(x) <- c(old, value)
}
else { htmlDependencies(x) <- value }
return(x)
}
However, without this function, you could still add your dependency in one line instead of three. I know that's not what you're looking for, but it's an option.
dtable$dependencies <- append(dtable$dependencies, list(dep))
With my example:
dep <- htmlDependency(
name = "colResize", version = "1.6.1",
src = c(href = "https://cdn.jsdelivr.net/gh/dhobi/datatables.colResize/"),
script = "jquery.dataTables.colResize.js",
stylesheet = "jquery.dataTables.colResize.css",
all_files = FALSE)
dtable <- datatable(iris, options = list(colResize = list()))
dtable$dependencies <- append(dtable$dependencies, list(dep))
dtable
A few days ago I wanted to install a certain package in R that wasn't available in the older version of R. I installed new version of R and R studio and now there is a problem. I can't install any packages, whenever I try, I get the following error:
Error in install.packages : STRING_ELT() can only be applied to a 'character vector', not a 'NULL'
Error in list.files(skeletonPath) :
STRING_ELT() can only be applied to a 'character vector', not a 'NULL'
Error in list.files(skeletonPath) :
STRING_ELT() can only be applied to a 'character vector', not a 'NULL'
Error in list.files(.rs.uniqueLibraryPaths(), full.names = TRUE) :
STRING_ELT() can only be applied to a 'character vector', not a 'NULL'
I also get the same error when I open R studio for the first time (without the first line of the code above). When I try to install packages manually by going to Tools, I get "R code execution error" message.
I'm not sure what's wrong, I don't understand that error.
Edit: After typing trace(utils:::unpackPkgZip, edit=TRUE) new window with the code opens:
function (pkg, pkgname, lib, libs_only = FALSE, lock = FALSE,
quiet = FALSE)
{
.zip.unpack <- function(zipname, dest) {
if (file.exists(zipname)) {
if ((unzip <- getOption("unzip")) != "internal") {
system(paste(shQuote(unzip), "-oq", zipname,
"-d", dest), show.output.on.console = FALSE,
invisible = TRUE)
}
else unzip(zipname, exdir = dest)
}
else stop(gettextf("zip file %s not found", sQuote(zipname)),
domain = NA)
}
lib <- normalizePath(lib, mustWork = TRUE)
tmpDir <- tempfile(, lib)
if (!dir.create(tmpDir))
stop(gettextf("unable to create temporary directory %s",
sQuote(normalizePath(tmpDir, mustWork = FALSE))),
domain = NA, call. = FALSE)
cDir <- getwd()
on.exit(setwd(cDir))
on.exit(unlink(tmpDir, recursive = TRUE), add = TRUE)
res <- .zip.unpack(pkg, tmpDir)
setwd(tmpDir)
res <- tools::checkMD5sums(pkgname, file.path(tmpDir, pkgname))
if (!quiet && !is.na(res) && res) {
cat(gettextf("package %s successfully unpacked and MD5 sums checked\n",
sQuote(pkgname)))
flush.console()
}
desc <- read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package",
"Type"))
if (desc[1L, "Type"] %in% "Translation") {
fp <- file.path(pkgname, "share", "locale")
if (file.exists(fp)) {
langs <- dir(fp)
for (lang in langs) {
path0 <- file.path(fp, lang, "LC_MESSAGES")
mos <- dir(path0, full.names = TRUE)
path <- file.path(R.home("share"), "locale",
lang, "LC_MESSAGES")
if (!file.exists(path))
if (!dir.create(path, FALSE, TRUE))
warning(gettextf("failed to create %s",
sQuote(path)), domain = NA)
res <- file.copy(mos, path, overwrite = TRUE)
if (any(!res))
warning(gettextf("failed to create %s", paste(sQuote(mos[!res]),
collapse = ",")), domain = NA)
}
}
fp <- file.path(pkgname, "library")
if (file.exists(fp)) {
spkgs <- dir(fp)
for (spkg in spkgs) {
langs <- dir(file.path(fp, spkg, "po"))
for (lang in langs) {
path0 <- file.path(fp, spkg, "po", lang, "LC_MESSAGES")
mos <- dir(path0, full.names = TRUE)
path <- file.path(R.home(), "library", spkg,
"po", lang, "LC_MESSAGES")
if (!file.exists(path))
if (!dir.create(path, FALSE, TRUE))
warning(gettextf("failed to create %s",
sQuote(path)), domain = NA)
res <- file.copy(mos, path, overwrite = TRUE)
if (any(!res))
warning(gettextf("failed to create %s",
paste(sQuote(mos[!res]), collapse = ",")),
domain = NA)
}
}
}
}
else {
instPath <- file.path(lib, pkgname)
if (identical(lock, "pkglock") || isTRUE(lock)) {
lockdir <- if (identical(lock, "pkglock"))
file.path(lib, paste0("00LOCK-", pkgname))
else file.path(lib, "00LOCK")
if (file.exists(lockdir)) {
stop(gettextf("ERROR: failed to lock directory %s for modifying\nTry removing %s",
sQuote(lib), sQuote(lockdir)), domain = NA)
}
dir.create(lockdir, recursive = TRUE)
if (!dir.exists(lockdir))
stop(gettextf("ERROR: failed to create lock directory %s",
sQuote(lockdir)), domain = NA)
if (file.exists(instPath)) {
file.copy(instPath, lockdir, recursive = TRUE)
on.exit({
if (restorePrevious) {
try(unlink(instPath, recursive = TRUE))
savedcopy <- file.path(lockdir, pkgname)
file.copy(savedcopy, lib, recursive = TRUE)
warning(gettextf("restored %s", sQuote(pkgname)),
domain = NA, call. = FALSE, immediate. = TRUE)
}
}, add = TRUE)
restorePrevious <- FALSE
}
on.exit(unlink(lockdir, recursive = TRUE), add = TRUE)
}
if (libs_only) {
if (!file_test("-d", file.path(instPath, "libs")))
warning(gettextf("there is no 'libs' directory in package %s",
sQuote(pkgname)), domain = NA, call. = FALSE,
immediate. = TRUE)
for (sub in c("i386", "x64")) if (file_test("-d",
file.path(tmpDir, pkgname, "libs", sub))) {
unlink(file.path(instPath, "libs", sub), recursive = TRUE)
ret <- file.copy(file.path(tmpDir, pkgname,
"libs", sub), file.path(instPath, "libs"),
recursive = TRUE)
if (any(!ret)) {
warning(gettextf("unable to move temporary installation %s to %s",
sQuote(normalizePath(file.path(tmpDir, pkgname,
"libs", sub), mustWork = FALSE)), sQuote(normalizePath(file.path(instPath,
"libs"), mustWork = FALSE))), domain = NA,
call. = FALSE, immediate. = TRUE)
restorePrevious <- TRUE
}
}
fi <- file.info(Sys.glob(file.path(instPath, "libs",
"*")))
dirs <- row.names(fi[fi$isdir %in% TRUE])
if (length(dirs)) {
descfile <- file.path(instPath, "DESCRIPTION")
olddesc <- readLines(descfile)
olddesc <- grep("^Archs:", olddesc, invert = TRUE,
value = TRUE, useBytes = TRUE)
newdesc <- c(olddesc, paste("Archs:", paste(basename(dirs),
collapse = ", ")))
writeLines(newdesc, descfile, useBytes = TRUE)
}
}
else {
ret <- unlink(instPath, recursive = TRUE, force = TRUE)
if (ret == 0) {
Sys.sleep(0.5)
ret <- file.rename(file.path(tmpDir, pkgname),
instPath)
if (!ret) {
warning(gettextf("unable to move temporary installation %s to %s",
sQuote(normalizePath(file.path(tmpDir, pkgname),
mustWork = FALSE)), sQuote(normalizePath(instPath,
mustWork = FALSE))), domain = NA, call. = FALSE,
immediate. = TRUE)
restorePrevious <- TRUE
}
}
else {
warning(gettextf("cannot remove prior installation of package %s",
sQuote(pkgname)), domain = NA, call. = FALSE,
immediate. = TRUE)
restorePrevious <- TRUE
}
}
}
}
Edit 2: Completely deleting all R versions from computer except for the newest version solved the problem.
In RStudio you go to Session and do the following things:
Clear Workspace
Terminate R
Restart R
Then close the program and restarted it. Some how that fix the issue.
For the error: "Error listing packages: R code execution error" try the following things:
Try restarting R using .rs.restartR()
Try removing the packages using remove.packages()
I am trying to modify an existing function by copy and pasting it to an R script, and assigning it to a new function object in my local environment. However the new function cannot find functions that are called to within the original function. How can I fix this without looking up and finding each function individually? I am guessing that the original function is somehow linked to the package or its dependencies and 'knows where to look' for the missing function, but I cannot figure out how to do this with my new copy-and-pasted function.
library("camtrapR")
Print the function name
activityDensity
The output here is the code for this function. I have omitted it here because it is long (and I have pasted it below), but I copy and paste the output of the function code exactly (see below where I assign this exact code to a new function), except for the last two lines of output, which I think are important:
<bytecode: 0x000000002a2d1e20>
<environment: namespace:camtrapR>
So now I assign the copy and pasted code from the output above to a new function with New <-
New <- function (recordTable, species, allSpecies = FALSE, speciesCol = "Species",
recordDateTimeCol = "DateTimeOriginal", recordDateTimeFormat = "%Y-%m-%d %H:%M:%S",
plotR = TRUE, writePNG = FALSE, plotDirectory, createDir = FALSE,
pngMaxPix = 1000, add.rug = TRUE, ...)
{
wd0 <- getwd()
mar0 <- par()$mar
on.exit(setwd(wd0))
on.exit(par(mar = mar0), add = TRUE)
recordTable <- dataFrameTibbleCheck(df = recordTable)
timeZone <- "UTC"
checkForSpacesInColumnNames(speciesCol = speciesCol, recordDateTimeCol = recordDateTimeCol)
if (!is.data.frame(recordTable))
stop("recordTable must be a data frame", call. = FALSE)
if (!speciesCol %in% colnames(recordTable))
stop(paste("speciesCol = \"", speciesCol, "\" is not a column name in recordTable",
sep = ""), call. = FALSE)
if (!recordDateTimeCol %in% colnames(recordTable))
stop(paste("recordDateTimeCol = \"", recordDateTimeCol,
"\" is not a column name in recordTable", sep = ""),
call. = FALSE)
stopifnot(is.logical(c(allSpecies, writePNG, plotR, createDir)))
if (allSpecies == FALSE) {
stopifnot(species %in% recordTable[, speciesCol])
stopifnot(hasArg(species))
}
recordTable$DateTime2 <- parseDateTimeObject(inputColumn = recordTable[,
recordDateTimeCol], dateTimeFormat = recordDateTimeFormat,
timeZone = timeZone)
recordTable$Time2 <- format(recordTable$DateTime2, format = "%H:%M:%S",
usetz = FALSE)
recordTable$Time.rad <- (as.numeric(as.POSIXct(strptime(recordTable$Time2,
format = "%H:%M:%S", tz = timeZone))) - as.numeric(as.POSIXct(strptime("0",
format = "%S", tz = timeZone))))/3600 * (pi/12)
if (isTRUE(writePNG)) {
if (hasArg(plotDirectory)) {
if (isTRUE(createDir)) {
dir.create(plotDirectory, recursive = TRUE, showWarnings = FALSE)
setwd(plotDirectory)
}
else {
stopifnot(file.exists(plotDirectory))
setwd(plotDirectory)
}
}
else {
stop("writePNG is TRUE. Please set plotDirectory",
call. = FALSE)
}
}
pngWidth <- pngMaxPix
pngHeight <- round(pngMaxPix * 0.8)
if (allSpecies == FALSE) {
subset_species <- subset(recordTable, recordTable[, speciesCol] ==
species)
if (nrow(subset_species) == 1)
stop(paste(species, "had only 1 record. Cannot estimate density."),
call. = FALSE)
try_error_tmp <- try({
if (isTRUE(writePNG))
png(filename = paste("activity_density_",
species, "_", Sys.Date(), ".png",
sep = ""), width = pngWidth, height = pngHeight,
units = "px", res = 96, type = "cairo")
if (isTRUE(writePNG) | isTRUE(plotR)) {
densityPlot(subset_species$Time.rad, main = paste("Activity of",
species), rug = add.rug, ...)
mtext(paste("number of records:", nrow(subset_species)),
side = 3, line = 0)
}
if (isTRUE(writePNG))
dev.off()
}, silent = TRUE)
if (class(try_error_tmp) == "try-error")
warning(paste(toupper(species), ": ", try_error_tmp[1],
" - SKIPPED", sep = ""), call. = FALSE)
}
else {
subset_species_list <- list()
for (i in 1:length(unique(recordTable[, speciesCol]))) {
spec.tmp <- unique(recordTable[, speciesCol])[i]
subset_species <- subset(recordTable, recordTable[,
speciesCol] == spec.tmp)
plot_main_title <- paste("Activity of", spec.tmp)
if (nrow(subset_species) == 1) {
warning(paste(toupper(spec.tmp), ": It had only 1 record. Cannot estimate density. - SKIPPED",
sep = ""), call. = FALSE)
next
}
else {
try_error_tmp <- try({
if (isTRUE(writePNG))
png(filename = paste("activity_density_",
spec.tmp, "_", Sys.Date(), ".png",
sep = ""), width = pngWidth, height = pngHeight,
units = "px", res = 96, type = "cairo")
if (isTRUE(writePNG) | isTRUE(plotR)) {
densityPlot(subset_species$Time.rad, main = plot_main_title,
rug = add.rug, ...)
mtext(paste("number of records:", nrow(subset_species)),
side = 3, line = 0)
}
if (isTRUE(writePNG))
dev.off()
}, silent = TRUE)
if (class(try_error_tmp) == "try-error")
warning(paste(toupper(spec.tmp), ": ",
try_error_tmp[1], " - SKIPPED",
sep = ""), call. = FALSE)
}
subset_species_list[[i]] <- subset_species$Time.rad
names(subset_species_list)[i] <- spec.tmp
}
}
if (allSpecies == FALSE) {
return(invisible(subset_species$Time.rad))
}
else {
return(invisible(subset_species_list))
}
}
Yet, when I try to run this new function (arguments omitted here for clarity), it can't find a function embedded within.
How can I somehow assign this function to look within the original package camtrapR for any dependencies, etc.? and why does the code output from the function not already do this?
New()
Error in dataFrameTibbleCheck(df = recordTable) :
could not find function "dataFrameTibbleCheck"
This answer here: https://stackoverflow.com/a/49277036/9096420 allows one to manually edit and save a function's code for each R session, but it is non-reproducible (not code) that can be shared or re-used.
If New is the new function copied from camtrapR then use
environment(New) <- asNamespace("camtrapR")
to ensure that the function calls in its body are looked up in the correct places.
The miniCRAN package's pkgAvail function is a basically a wrapper to the available.packages function. What I'm having trouble with is finding the definition of contribUrl() function call it makes in the repo parameter.
I understand what it is supposed to do - allows for a contrib url of a R version explicitly identified, instead of using R.version.
But where is contribUrl() defined?
available.packages
utils::available.packages(contribUrl(repos, type = type,
Rversion = Rversion), type = type, filters = list())
For context, this is where the function call is from:
pkgAvail <- function (repos = getOption("repos"), type = "source", Rversion = R.version)
{
if (!grepl("^http://|file:///", repos[1]) && file.exists(repos[1])) {
repos <- paste0("file:///", normalizePath(repos[1], mustWork = FALSE,
winslash = "/"))
}
else {
if (!is.null(names(repos)) && isTRUE(unname(repos["CRAN"]) ==
"#CRAN#")) {
repos <- MRAN()
}
}
utils::available.packages(contribUrl(repos, type = type,
Rversion = Rversion), type = type, filters = list())
}
It's a modified copy of contrib.url from utils. It's defined here:
https://github.com/RevolutionAnalytics/miniCRAN/blob/master/R/pkgDep.R
Here's the definition:
# Modified copy of utils::contrib.url()
contribUrl <- function (repos, type = getOption("pkgType"), Rversion = R.version) {
Rversion <- twodigitRversion(Rversion)
if (type == "both")
type <- "source"
if (type == "binary")
type <- .Platform$pkgType
if (is.null(repos))
return(NULL)
if ("#CRAN#" %in% repos && interactive()) {
cat(gettext("--- Please select a CRAN mirror for use in this session ---"),
"\n", sep = "")
flush.console()
chooseCRANmirror()
m <- match("#CRAN#", repos)
nm <- names(repos)
repos[m] <- getOption("repos")["CRAN"]
if (is.null(nm))
nm <- rep("", length(repos))
nm[m] <- "CRAN"
names(repos) <- nm
}
if ("#CRAN#" %in% repos)
stop("trying to use CRAN without setting a mirror")
ver <- Rversion
mac.path <- "macosx"
if (substr(type, 1L, 11L) == "mac.binary.") {
mac.path <- paste(mac.path, substring(type, 12L), sep = "/")
type <- "mac.binary"
}
res <- switch(type,
source = paste(gsub("/$", "", repos), "src", "contrib", sep = "/"),
mac.binary = paste(gsub("/$", "", repos), "bin", mac.path, "contrib", ver, sep = "/"),
win.binary = paste(gsub("/$", "", repos), "bin", "windows", "contrib", ver, sep = "/"))
res
}
Here's the original function:
> utils::contrib.url
function (repos, type = getOption("pkgType"))
{
type <- resolvePkgType(type)
if (is.null(repos))
return(NULL)
if ("#CRAN#" %in% repos && interactive()) {
cat(gettext("--- Please select a CRAN mirror for use in this session ---"),
"\n", sep = "")
flush.console()
chooseCRANmirror()
m <- match("#CRAN#", repos)
nm <- names(repos)
repos[m] <- getOption("repos")["CRAN"]
if (is.null(nm))
nm <- rep("", length(repos))
nm[m] <- "CRAN"
names(repos) <- nm
}
if ("#CRAN#" %in% repos)
stop("trying to use CRAN without setting a mirror")
ver <- paste(R.version$major, strsplit(R.version$minor, ".",
fixed = TRUE)[[1L]][1L], sep = ".")
mac.path <- "macosx"
if (substr(type, 1L, 11L) == "mac.binary.") {
mac.path <- paste(mac.path, substring(type, 12L), sep = "/")
type <- "mac.binary"
}
res <- switch(type, source = paste(gsub("/$", "", repos),
"src", "contrib", sep = "/"), mac.binary = paste(gsub("/$",
"", repos), "bin", mac.path, "contrib", ver, sep = "/"),
win.binary = paste(gsub("/$", "", repos), "bin", "windows",
"contrib", ver, sep = "/"))
res
}
<bytecode: 0x0000000007708e90>
<environment: namespace:utils>
I wrote 2 functions to archive objects from R (with their names - that's really important for me) and, if an object is of class lm, to archive data used to conduct this model.
My code is below :
archive_object_and_data <- function(object, archiveData = TRUE, rememberName = TRUE){
object <- deparse(substitute(object))
md5hash <- digest(object)
dir <- paste0(getwd(), "/")
dir.create(file.path(dir, md5hash), showWarnings = FALSE)
if (rememberName){
save( file = paste0(dir, md5hash, "/obj.rda"), ascii = TRUE, list = objectName,
envir = parent.frame(2))
}else{
save( file = paste0(dir, md5hash, "/obj2.rda"), ascii = TRUE, list =objectName,
envir = parent.frame(5))}
if ( archiveData )
archiveDataFromObj( object, md5hash, changeBool = FALSE )
}
#
archiveDataFromObj <- function (object, md5hash, changeBool = TRUE)
UseMethod("archiveDataFromObj")
archiveDataFromObj.default <- function(object, md5hash, changeBool = TRUE) {
}
archiveDataFromObj.lm <- function(object, md5hash, changeBool = TRUE) {
extractedDF <- object$model
md5hashDF <- archive_object_and_data(extractedDF, rememberName = changeBool)
}
And the object I want to archive looks like this :
data( iris )
test_data <- iris[,-5]
model2 <- lm(Sepal.Length~. , data=test_data)
archive_object_and_data(model2)
And error appears like this :
Error in save(file = paste0(dir, md5hash, "/obj2.rda"), ascii = TRUE, :
object ‘extractedDF’ not found
6 stop(sprintf(ngettext(n, "object %s not found", "objects %s not found"),
paste(sQuote(list[!ok]), collapse = ", ")), domain = NA)
5 save(file = paste0(dir, md5hash, "/obj2.rda"), ascii = TRUE,
list = objectName, envir = parent.frame(5))
4 archive_object_and_data(extractedDF, rememberName = changeBool) at archiveDataFromObj.R
3 archiveDataFromObj.lm(object, md5hash, changeBool = FALSE) at archiveDataFromObj.R#1
2 archiveDataFromObj(object, md5hash, changeBool = FALSE) at archive_object_and_data.R
1 archive_object_and_data(model2)
Can any1 help me with this problem?
It looks like there's a problem with that line :(
}else{
save( file = paste0(dir, md5hash, "/obj2.rda"), ascii = TRUE, list =objectName,
envir = parent.frame(5))}