How to fix save.ffdf on remote server - r

I can't save.ffdf or move.ffdf. Also, the deprecated ffdfsave is broken.
require(ff);require(ffbase)
x <- data.frame(matrix(rnorm(5*5),ncol=5))
x <- as.ffdf(x)
save.ffdf(x,getwd())
I will get the following error:
Error infilename<-.ff(tmp, value = "/home/... Deleted .../path$X0.0.ff") :
ff file rename from '/tmp/RtmpasUciV/ffdf346c5f0daaea.ff' to '/home/... Deleted .../path$X0.0.ff' failed
The only thing that will work is:
require(ff);require(ffbase)
x <- data.frame(matrix(rnorm(5*5),ncol=5))
x <- as.ffdf(x)
save.ffdf(x,tempfile())
Note that when I call this on my local terminal it works. It's just when I try this on a remote server it does not work.
I will also get the error underneath the above error:
In addition: Warning message:
In file.rename(oldnam, value) :
cannot rename file '/tmp/RtmpasUciV/ffdf346c5f0daaea.ff' to '/home/... Deleted .../path$X0.0.ff', reason 'Invalid cross-device link'

Related

Trouble with working directory and {reticulate}

I'm trying to use {reticulate} to load in a .pkl file. So far I've just loaded the package and tried to import pandas, i.e.:
library(reticulate)
pd<-import("pandas")
For some reason I'm getting this error, but can't make any sense of it:
Error: invalid version specification ''/home'', '..EXE was started with the above path as the current directory.', '. paths are not supported. Defaulting to Windows directory.'
In addition: Warning message:
In if (grepl("\\.$", v)) v <- paste0(v, "9000") :
the condition has length > 1 and only the first element will be used
Any tips?

Error in unserialize(con) : unknown input format

I am downloading a file from Azure to a connection. The download appears to go through but unserializing gives an error. Any ideas what may be going wrong or how to go about debugging?
con <- rawConnection(raw(0), "r+")
storage_download(AzureContainer, src="sourcefile.fst", dest=con)
unserialize(con)
Error in unserialize(con) : unknown input format

How to eliminate security concern while accessing to the file through program in R in Windows?

While accessing to CSV file from disk with the help of the R program, where a path to the CSV file is provided in the configuration file ( A path is like "testData/Amazon S3/Inventory/Accounts.csv" which is provided in the Configuration file and cfig[2]$save.location is variable who is having value of this path accessed from Configuration file). Few lines of code are below
path <- cfig[2]$save.location
test_data <- fread(path,stringsAsFactors = FALSE,drop=col_ignor,blank.lines.skip = TRUE)
but it gave the message below:
Taking input= as a system command ('testData/Amazon
S3/Inventory/Accounts.csv') and a variable has been used in the
expression passed to input=. Please use fread(cmd=...). There is a
security concern if you are creating an app and the app could have a
malicious user and the app is not running in a secure environment;
e.g. the app is running as root. Please read item 5 in the NEWS file
for v1.11.6 for more information and for the option to suppress this
message.
'testData' is not recognized as an internal or external
command, operable program or batch file. Warning messages:
1: In (if
(.Platform$OS.type == "unix") system else shell)(paste0("(", :
'(testData/Amazon S3/Inventory/Accounts.csv) >
C:\Users\sharmb5\AppData\Local\Temp\RtmpOa25kH\filea78b5351f1'
execution failed with error code 1.
2: In fread(cfig[2]$save.location,
stringsAsFactors = FALSE, drop = col_ignor, : File
'C:\Users\sharmb5\AppData\Local\Temp\RtmpOa25kH\filea78b5351f1' has
size 0. Returning a NULL data.table.
when the following line of code executes,
config[4]$save.location <- stri_replace_all(config[4]$save.location, cp_val, fixed = cp_key)
It gives an error like as, Error in [<-.data.table(*tmp*, j, value = list(TestCaseID = "C419760", : Supplied 14 columns to be assigned 15 items. Please see NEWS for v1.12.2.
The above error was a warning but after manually updating of packages. This warning turns into an error. What will be the reason behind this issue and how to solve it? Thanks for Advance!!!

Error using DEXSeqDataSetFromHTSeq

Currently I am trying to understand DEXSeq package. I have a design tsv file and 7 files which contains Counts. Now would like to run the following command
library("DEXSeq");
design=read.table("dexseq_design.tsv", header=TRUE, row.names=1);
ecs = DEXSeqDataSetFromHTSeq(countfiles=c("M0.txt", "M1.txt", "M2.txt", "M3.txt", "M4.txt", "M5.txt", "M6.txt", "M7.txt"), design=design, flattenedfile="genome.chr.gff");
The last command gives and error
Error in class(sampleData) %in% c("data.frame") :
error in evaluating the argument 'x' in selecting a method for function '%in%':
Error: argument "sampleData" is missing, with no default
What does this error means and how to fix it? While loading the package DEXSeq there was a warning
Warning message:
replacing previous import by ‘ggplot2::Position’ when loading ‘DESeq2’

How to elegantly handle errors in R when state needs to be cleaned up?

What is the best was to handle errors in R? I want to be able to both abstract away stack traces from the end user of my script, as well as clean up any temporary variables and state i may be working with.
So i suppose my question is two fold:
Most importantly, how do i properly handle cleaning up state when handling errors?
How do i extract, useful, nice information from R's error messages, without internal
stuff being spit out?
At the moment, I have something which looks like this, but (1) it seems horribly inelegant, and (2) still gives me horrible error messages.
# Create some temporary working state and variables to clean up
file <- "somefile"
working.dir <- getwd()
setwd("../") # Go somewhere else
saf.default <- getOption("stringsAsFactors")
options(stringsAsFactors = FALSE)
# Now lets try to open the file, but it doesn't work (for whatever reason)
# I want to clean up the state, stop, and wrap the error string with a nicer
# message
tryCatch({
# Need to embed the tryCatch because we still need some of the state variables
# for the error message
tryCatch({
f <- read.table(file)
}, error = function(err.msg) {
# Can't clean up here, we still need the `file variable!
stop("Could not open file '", file, "' with error message:\n", print(err.msg),
call.=FALSE)
})
}, error = function(err.msg) {
# Now we can clean up state
setwd(working.dir)
options(stringsAsFactors = saf.default)
rm(file, working.dir, saf.default,
envir=globalenv()) # This also seems awful?
stop(print(err.msg), call.=FALSE)
})
# Do more stuff, get more state, handle errors, then clean up.
# I.e can't use `finally` in previous tryCatch!
The error message from this comes out as, still lots of ugly internals:
# <simpleError in file(file, "rt"): cannot open the connection>
# <simpleError: Could not open file 'somefile' with error message:
# Error in file(file, "rt"): cannot open the connection
>
# Error: Could not open file 'somefile' with error message:
# Error in file(file, "rt"): cannot open the connection
# In addition: Warning messages:
# 1: In file(file, "rt") :
# cannot open file 'somefile': No such file or directory
# 2: In stop(print(err.msg), call. = FALSE) :
# additional arguments ignored in stop()
>
I would isolate any state-changing code into its own function, and use on.exit. This guarantees that cleanup will happen, no matter if an error occurs.
readFile <- function(.....)
{
on.exit({
setwd(cur.dir)
options(stringsAsFactors=saf)
})
cur.dir <- getwd()
saf <- getOption("stringsAsFactors")
setwd("new/dir")
options(stringsAsFactors=FALSE)
....
}

Resources