RPackage library exception (error 1000) - r

I have the following code in an Execute R Module.
# Input
data1 <- maml.mapInputPort(1) # Qualitative with 8 variables
install.packages("src/graphics.zip", lib.loc = ".", repos = NULL, verbose =
TRUE)
install.packages("src/grDevices.zip", lib.loc = ".", repos = NULL, verbose =
TRUE)
install.packages("src/stats.zip", lib.loc = ".", repos = NULL, verbose =
TRUE)
install.packages("src/utils.zip", lib.loc = ".", repos = NULL, verbose =
TRUE)
install.packages("src/MASS.zip", lib.loc = ".", repos = NULL, verbose =
TRUE)
success <- library("MASS", lib.loc = ".", logical.return = TRUE, verbose =
TRUE)
library(MASS)
mca <- mca(data1, nf = 10)
mca1 <- data.frame(mca$rs)
# Output
maml.mapOutputPort("mca1");
When I execute I am getting the following error:
RPackage library exception: Attempting to obtain R output before invoking execution process. (Error 1000)
But it is working fine in RStudio.
I also have a node that does the same process and it works without errors. I have executed it several times, sometimes it has worked for me and then it has returned error.
Please let me know what the issue is.
With regards,
Celia

Related

data.table::fread error when converting MAF files to data table

I want to merge the 50 MAF files with the sample information so that I can read it as a data.table and subset it.
library(maftools)
# Load MAF files
maf = system.file("extdata", list.files(path="mafs/"), package="maftools")
# Load sample information
si <- system.file("extdata", "sample-information.tsv", package="maftools")
d = read.maf(maf=maf, clinicalData=si)
Traceback:
Error in data.table::fread(file = maf, sep = "\t", stringsAsFactors = FALSE, :
File '' does not exist or is non-readable. getwd()=='C:/Users/User/Documents/VanAllen'
> traceback()
3: stop("File '", file, "' does not exist or is non-readable. getwd()=='",
getwd(), "'")
2: data.table::fread(file = maf, sep = "\t", stringsAsFactors = FALSE,
verbose = FALSE, data.table = TRUE, showProgress = TRUE,
header = TRUE, fill = TRUE, skip = "Hugo_Symbol", quote = "")
1: read.maf(maf = maf, clinicalData = si)
1: data.table::fread(input = maf)
Maftools documentation:
https://www.bioconductor.org/packages/release/bioc/manuals/maftools/man/maftools.pdf
When I run your code, maf indeed points to no character ( "" ), which of course cannot be read by fread. However when I try
fread("R/x86_64-pc-linux-gnu-library/3.6/maftools/extdata/brca.maf.gz")
it works as expected.

I can't install packages in R

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()

Unable to read Excel file in R-studio

install.packages('read_excel')
library(xlsx)
read.xlsx(path, sheet = "C:/Users/Vikas Singh/Desktop/Data KNN.xlsx",sheet=2 , range = NULL, col_names = TRUE, col_types = NULL, na = "", trim_ws = TRUE, skip = 0, n_max = Inf)
Even after using the above code I'm getting an error message no function read.xlsx
The read.xlsx is a function from the openxlsx package.
You need install and load the readxl package.
install.packages("readxl")
library(readxl)
Then try the following code:
read_excel(path = "C:/Users/Vikas Singh/Desktop/Data KNN.xlsx", sheet = 2, col_names = TRUE, col_types = NULL, na = "", skip = 0)
You have to install the openxlsx package. Please read the according documentation here. Try out the following code:
install.packages("openxlsx")
library(openxlsx)
read.xlsx(xlsxFile = "C:/Users/Vikas Singh/Desktop/DataKNN.xlsx", sheet= <sheet_index> , <... all_your_other_arguments>)

Error in checkForRemoteErrors(val) :

I am currently running an ensemble niche model analyses through a Linux cluster in a CentOs6 environment. The package I am using is SSDM. My code is as follows:
Env <- load_var(path = getwd(), files = NULL, format = c(".grd", ".tif", ".asc",
".sdat", ".rst", ".nc", ".envi", ".bil", ".img"), categorical = "af_anthrome.asc",
Norm = TRUE, tmp = TRUE, verbose = TRUE, GUI = FALSE)
Env
head(Env)
warnings()
Occurrences <- load_occ(path = getwd(), Env, file =
"Final_African_Bird_occurrence_rarefied_points.txt",
Xcol = "decimallon", Ycol = "decimallat", Spcol =
"species", GeoRes = FALSE,
sep = ",", verbose = TRUE, GUI = FALSE)
head(Occurrences)
warnings()
SSDM <- stack_modelling(c("GLM", "GAM", "MARS", "GBM", "RF", "CTA",
"MAXENT", "ANN", "SVM"), Occurrences, Env, Xcol = "decimallon",
Ycol = "decimallat", Pcol = NULL, Spcol = "species", rep
= 1,
name = "Stack", save = TRUE, path = getwd(), PA = NULL,
cv = "holdout", cv.param = c(0.75, 1), thresh = 1001,
axes.metric = "Pearson", uncertainty = TRUE, tmp = TRUE,
ensemble.metric = c("AUC", "Kappa", "sensitivity", "specificity"), ensemble.thresh = c(0.75, 0.75, 0.75, 0.75), weight = TRUE,
method = "bSSDM", metric = "SES", range = NULL,
endemism = NULL, verbose = TRUE, GUI = FALSE, cores = 125)
save.stack(SSDM, name = "Bird", path = getwd(),
verbose = TRUE, GUI = FALSE)
When running the stack_modelling function I get this Error message:
Error in checkForRemoteErrors(val) :
125 nodes produced errors; first error: comparison of these types is not
implemented
Calls: stack_modelling ... clusterApply -> staticClusterApply ->
checkForRemoteErrors
In addition: Warning message:
In stack_modelling(c("GLM", "GAM", "MARS", "GBM", "RF", "CTA", "MAXENT", :
It seems you attributed more cores than your CPU have !
Execution halted
Error in unserialize(node$con) : error reading from connection
Calls: <Anonymous> ... doTryCatch -> recvData -> recvData.SOCKnode ->
unserialize
In addition: Warning message:
In eval(e, x, parent.frame()) :
Incompatible methods ("Ops.data.frame", "Ops.factor") for "=="
Execution halted
I understand that I may have attributed more cores than I have access to but this same error message crops up when I use a fraction of the cores. I am not entirely sure what this error message is trying to tell me or how to fix it as I am new to working on a cluster. Is it a problem with parallel processing of the data? Is there a line of code which can help me fix this issue?
Thanks

Update specific R package from local source

I have R installed on a machine without internet access. Is it possible to update a specific package from a local source archive? What would be the right way to do it?
install.packages(pkgs, lib, repos = getOption("repos"),
contriburl = contrib.url(repos, type),
method, available = NULL, destdir = NULL,
dependencies = NA, type = getOption("pkgType"),
configure.args = getOption("configure.args"),
configure.vars = getOption("configure.vars"),
clean = FALSE, Ncpus = getOption("Ncpus", 1L),
verbose = getOption("verbose"),
libs_only = FALSE, INSTALL_opts, quiet = FALSE,
keep_outputs = FALSE, ...)
Use above command. for more help refer https://stat.ethz.ch/R-manual/R-devel/library/utils/html/install.packages.html
For updating: https://stat.ethz.ch/R-manual/R-devel/library/utils/html/update.packages.html

Resources