Uploading a model to synapse - r

I tried to upload a data model to Synapse, and I got the following error message (from remote console):
Error in if (grepl("/$", filePath)) { : argument is of length zero In
addition: Warning messages: 1: In file.copy(object$getCacheDir(),
path, recursive = TRUE) : problem creating directory
/home/creighto#bcm.edu/scratch/tmp/RtmpHjLEQh/cacheRoot5e4dbe7c02d/archive.zip_unpacked/.R_OBJECTS:
No space left on device 2: In unzip(filename, exdir = destdir) : error
1 in extracting from zip file.
Also my directory has frozen up, and I cannot seem to access files. Have I exceeded a space limit here?

Sorry to state the obvious, but it does look like you've ran out of space: you can't unzip file due to space, so you can't create a directory. Can you reduce the file size?

Related

R Raster error: Cannot create a RasterLayer object from this file. (file does not exist)

Trying to pull in and scale a Landsat image but receive an error, this seems to be a somewhat common issue given the older questions and various ways of creating a RasterLayer object.
After loading the libraries I need I get to this and hit an issue:
Directory <- "D:/Geo Files/LANDSAT"
prefix <- "CU_LC08.001_"
suffix <- "_doy2020222_aid0001.tif"
## Get band 2 reflectance (blue, 0.45-0.515 micron)
sr2 <- raster(paste0(Directory,prefix,"SRB2",suffix))
Error in .local(.Object, ...) :
*Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", :
Cannot create a RasterLayer object from this file. (file does not exist)*
> sr2 = sr2*0.0001 #Scale
Error: object 'sr2' not found
The full name of the first (SRB2) file I want to use is:
CU_LC08.001_SRB2_doy2020222_aid0001.tif - the name of the file as it's downloaded, unchanged.
The rest of the code continues through the other files to go through each SRB and later calculate NDVI, etc
i.e. ## Get band 3 reflectance (green, 0.533-0.590 micron) sr3 <- raster(paste0(Directory,prefix,"SRB3",suffix)) sr3 = sr3*0.0001 #Scale
Edit 1: I tried using try using \ instead of forward slashes and got exactly the same error.
R version is R-4.0.3
Any help would be appreciated, this was provided to us in a hackathon and I am new to R, it should be simple to run but if the file cannot be read..?
EDIT 2: The issue was with the end of the path, it needed "\"
Directory <- "D:\\Geo Files\\LANDSAT\\"
But when trying to get another file to work from a different folder later in the code, the same issue appears, and the above fix did nothing:
Directory <- "D:\\Geo Files\\ECOSTRESS\\USCities\\"
LST_ECO <- raster(paste0(Directory,"SDS_LST_doy2020260040819_aid0001.tif"))
Error in .local(.Object, ...) :
Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", :
Cannot create a RasterLayer object from this file. (file does not exist)
EDIT 3: Changed \Geo Files\ to "\GeoFiles\" as suggested, tried again but problem still occurs as above.
I had the same issue and the following was the process that finally worked.
# location of the file
loc_1 = "D:\\Geo Files\\ECOSTRESS\\USCities\\SDS_LST_doy2020260040819_aid0001.tif"
# check if the file can be read into r
tif1 = readr::read_file(loc_1)
It raised the following error (edited):
Error: Cannot read file "D:\\Geo Files\\ECOSTRESS\\USCities\\SDS_LST_doy2020260040819_aid0001.tif": The cloud file provider is not running.
The reason was because R could not read the file as it was in an online folder.
Confirm if the file is available offline. If it can be read by read_file function then the raster function should work.
I had the same issue
i was loading a raster file from my local storage
I added ".tif" extension to the name of the file and it worked

Finding and setting the working directory within a super computer

Obviously one can find and set working directories with getwd() and setwd(). This question is a bit more complicated. I'm running two files on a super computer (one is a regular R file which calls the other file (a .stan file). The way I submit work to the super computer is that I have to zip a folder containing the data, the .R file, and the .stan file. I upload this folder, and I pull this folder by setting it as one of the parameters in the super computer. I call the data using the standard read.csv() command and everything is hunky dory.
However, when I call the .stan file from the .R file, it can't access it because it needs to know the working directory.
This is the error I get:
> fit <- stan(file="ace_thresholds.stan", data=stanData, cores = 4)
Error in file(fname, "rt") : cannot open the connection
In addition: Warning messages:
1: In normalizePath(file) :
path[1]="ace_thresholds.stan": No such file or directory
2: In file(fname, "rt") :
cannot open file 'ace_thresholds.stan': No such file or directory
Error in get_model_strcode(file, model_code) :
cannot open model file "ace_thresholds.stan"
Calls: stan -> stan_model -> stanc -> get_model_strcode
Execution halted
When I tried setting the working directory to the unzipped NSG_stan folder (which is what I assumed the wd to be, I received this error:
fit <- stan(file="NSG_stan/ace_thresholds.stan", data=stanData, cores = 4)
Error in file(fname, "rt") : cannot open the connection
In addition: Warning messages:
1: In normalizePath(file) :
path[1]="NSG_stan/ace_thresholds.stan": No such file or directory
2: In file(fname, "rt") :
cannot open file 'NSG_stan/ace_thresholds.stan': No such file or directory
Error in get_model_strcode(file, model_code) :
cannot open model file "NSG_stan/ace_thresholds.stan"
Calls: stan -> stan_model -> stanc -> get_model_strcode
Execution halted
So I tried running print(getwd()) within the script and in the printout I see that the wd is
"/projects/ps-nsg/home/nsguser/ngbw/workspace/NGBW-JOB-RTOOL_TG-EBE9CDBF28BF42AF8CB6EC9355006B3E/NSG_stan"
which means that the working directory will shift with every job. So to accurately set the working directory, I'd need to set it to the current folder within the script. I looked for various posts on how to do this like the following
# install.packages("rstudioapi") # run this if it's your first time using it to install
library(rstudioapi) # load it
# the following line is for getting the path of your current open file
current_path <- getActiveDocumentContext()$path
# The next line set the working directory to the relevant one:
setwd(dirname(current_path ))
# you can make sure you are in the right directory
print( getwd() )
The issue with this is that it's a super computer, so it's difficult to install packages, because every time I want to install something, I have to email the folks associated with the super comp and that all takes time.
I've looked over this thread as well: R command for setting working directory to source file location in Rstudio. Appears to be a lot of dissent over what works. I tried a couple of them, and they didn't work.
setwd(getSrcDirectory()[1])
this.dir <- dirname(parent.frame(2)$ofile)
setwd(this.dir)
I've included the .R file below, in the event that it helps, but I think this is probably a pretty easy answer for someone with a decent amount of coding experience.
.R file (so it's the "ace_thresholds.stan" file that I either need to link to the current wd or to include the code that would set the wd, such that this "ace_thresholds.stan" call would work. Does that make sense?
Thanks much!
dat <- ace.threshold.t2.samp
dat <- subset(dat, !is.na(rw))
dat$condition <- factor(dat$condition)
dat$pid <- factor(dat$pid)
nTotal <- dim(dat)[1]
nCond <- length(unique(dat$condition))
nSubj <- length(unique(dat$pid))
intensity <- dat$rw
condition <- as.numeric(dat$condition)
pid <- as.numeric(dat$pid)
correct <- dat$correct_button == "correct"
chancePerformance <- 1/2
stanData <- list(nTotal=nTotal, nLevels=nCond, nSubj = nSubj, subject = pid, intensity=intensity, level=condition, correct=correct, chancePerformance=chancePerformance)
fit.rw <- stan(file="ace_thresholds.stan", data=stanData, cores = 4, control=list(max_treedepth=15, adapt_delta=0.90))

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!!!

In R, after installed a package,' pixmap', Error in file(file, open = "rb") : cannot open the connection

I'm learning R programming, using the book, "The Art of R Programming".
In chapter 3.2.3 Extended Example: Image Manipulation. The author Matloff tries to use a Mount Rushmore gray-scale image to illustrate that the image is stored in matrix. He used a library called pixmap. And I downloaded the package, installed it.
> library(pixmap)
> mtrush1 <- read.pnm("mtrush1.pgm")
> mtrush1
Pixmap image
Type : pixmapGrey
Size : 194x259
Resolution : 1x1
Bounding box : 0 0 259 194
> plot(mtrush1)
This is what the book has written, and I tried to run this, but got the error message,
> library(pixmap)
> mtrush1 <- read.pnm("mtrush1.pgm")
Error in file(file, open = "rb") : cannot open the connection
In addition: Warning message:
In file(file, open = "rb") :
cannot open file 'mtrush1.pgm': No such file or directory
starting httpd help server ... done
What does this mean? cannot open the connection? And also the mtrush1.pgm does not exist? How should I fix it here? Any help? Much appreciated.
Summary:
Add the argument cellres=1 to your function call and you should be fine.
Answer:
The second error you saw--Warning message: In rep(cellres, length = 2) : 'x' is NULL so the result will be NULL--is because you haven't set the cellres argument and, as a result, "cellres" assumes its default value (i.e. 'NULL'--hence the warning). For what you're working on, setting the cellres argument to 1 will do the trick (though you can pass in a two-element vector with unequal values and see just how it affects your figure by plotting the resulting object).
Note: Though it's a little late to be answering, I figure that since I had the same problem earlier today (and since Google was no help) a response was probably warranted.
This means that the file mtrush1.pgm is not in current directory. You should either setwd to the directory that contains this file, or specify the complete path in read.pnm.
For the file mtrush1.pgm, you can download it from http://heather.cs.ucdavis.edu/~matloff/
The file mtrush1.pgm and the R scripts from the book "The Art Of R Programming" can be found at this GitHub site.

Trouble with posting slidify to Dropbox

I created a slidify slideshow, but when I am trying to drop in into my dropbox account into Public folder I get a warning:
publish("Slides", host = "dropbox")
Creating slide directory at ~/Dropbox/Public/Slides
Copying files to ~/Dropbox/Public/Slides
[1] FALSE
Warning messages:
1: In file.copy(".", drop_dir, overwrite = F, recursive = TRUE) :
'recursive' will be ignored as 'to' is not a single existing directory
2: In file.create(to[okay]) :
cannot create file '~/Dropbox/Public/Slides', reason 'No such file or directory'
I tried to create a hard symbolic link as http://thiagosilva.wordpress.com/2013/02/17/installing-slidify-on-a-windows-machine/ suggests.
But the warning is still there...
Any ideas?
Best Regards!

Resources