I've got a script inside a shared Google Drive folder of our company.
I simply try to
save.image(file='.RData')
but I'm getting the bellow error
Error in save(list = names(.GlobalEnv), file = outfile, version = version, :
error writing to connection
Any tips on how I can resolve it?
Related
I'm very new to R and this is my first post here.
I'm using Rstudio (Version 1.4.1717; R version 4.1.0) and am trying to save my workspace image to a file.
I'm using this code:
save.image("C:/Users/../Documents")
However, I get the following error:
Error in save.image("C:/Users/../Documents") :
image could not be renamed and is left in C:/Users/../DocumentsTmp1
In addition: Warning message:
In file.rename(outfile, file) :
cannot rename file 'C:/Users/../DocumentsTmp1' to 'C:/Users/../Documents', reason 'Access is denied'
The "DocumentsTmp1" file is created in "C:/Users/..", but it seems it can't subsequently be renamed and stored in the "C:/Users/../Documents" file.
I've tried running Rstudio as Administrator, but this didn't help. I am able to save files to the specified file using the Windows file explorer. I've also tried saving to a different file but get the same error. I hope someone can help!
I am downloading a large xlsx file as a part of a function. This file is removed with file.remove() in linux and mac but I have permission denied in windows machines. Below is the code for my function.
download.file(
'http://mirtarbase.mbc.nctu.edu.tw/cache/download/7.0/miRTarBase_MTI.xlsx',
'miRTarBase.xlsx', mode = "wb")
readxl::read_excel('miRTarBase.xlsx') -> miRTarBase
write.csv(miRTarBase, 'miRTarBase.csv')
read.csv('miRTarBase.csv', row.names = 1) -> miRTarBase
file.remove("miRTarBase.xlsx")
I get the following error message in my console
Warning message:
In file.remove("miRTarBase.xlsx") :
cannot remove file 'miRTarBase.xlsx', reason 'Permission denied'.
Again this warning only appears in windows.
Furthermore, after checking the properties of the file itself the 'Read-only' attribute is unchecked.
Following this, the following code works perfectly fine so I do not think the issue is with the folder either.
file.remove("miRTarBase.csv")
I believe the issue lies in how .xlsx files are treated in windows.
When I try to delete the .xlsx file while Rstudio is still running I get a File in use warning message. After closing the R session the .xlsx file can be deleted with no hassle.
This has confused me because I am not used to working with windows. Has anyone had this issue before? Would appreciate any help that can be given. Many thanks.
Have you tried saving as a temporary file in windows?
tmp <- tempfile()
download.file(
'http://mirtarbase.mbc.nctu.edu.tw/cache/download/7.0/miRTarBase_MTI.xlsx', tmp, mode = "wb")
readxl::read_excel(tmp) -> miRTarBase
write.csv(miRTarBase, 'miRTarBase.csv')
read.csv('miRTarBase.csv', row.names = 1) -> miRTarBase
file.remove(tmp)
I am trying to download a set of NetCDF files from: ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/nwm/prod/nwm.20180425/medium_range/
When I manually download the files I have no issues connecting, but when I use download.file and attempt to connect I get the following error:
Assertion failed!
Program: C:\Program Files\Rstudio\bin\rsession.exe
File: nc4file.c, Line 2771
Expression: 0
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
I have attempted to run the code in R without R studio and got the same result.
My abbreviated code is as followed:
library("ncdf4")
library("ncdf4.helpers")
download.file("ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/nwm/prod/nwm.20180425/medium_range/nwm.t00z.medium_range.channel_rt.f006.conus.nc","c:/users/nt/desktop/nwm.t00z.medium_range.channel_rt.f006.conus.nc")
temp = nc_open("c:/users/nt/desktop/nwm.t00z.medium_range.channel_rt.f006.conus.nc")
Adding mode = 'wb' to the download.file arguments solves the issue for me. I've had the same problem when downloading PDFs
download.file("ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/nwm/prod/nwm.20180425/medium_range/nwm.t00z.medium_range.channel_rt.f006.conus.nc","C:/teste/teste.nc", mode = 'wb')
I'm hosting my first shiny app from www.shinyapps.io. My r script uses a glm I created locally that I have stored as a .RDS file.
How can I read this file into my application directly using a free file host such as dropbox or google drive? (or another better alternative?)
test<-readRDS(gzcon(url("https://www.dropbox.com/s/p3bk57sqvlra1ze/strModel.RDS?dl=0")))
however, I get the error:
Error in readRDS(gzcon(url("https://www.dropbox.com/s/p3bk57sqvlra1ze/strModel.RDS?dl=0"))) :
unknown input format
I assume this is because the URL doesn't lead directly to the file but rather a landing page for dropbox?
That being said, I can't seem to find any free file hosting sites that have that functionality.
As always, I'm sure the solution is very obvious, any help is appreciated.
I figured it out. Hosted the file in a GitHub repository. From there I was able to copy the link to the raw file and placed that link in the readRDS(gzcon(url())) wrappers.
Remotely reading using readRDS() can be disappointing. You might want to try this wrapper that saves the data set to a temporary location before reading it locally:
readRDS_remote <- function(file, quiet = TRUE) {
if (grepl("^http", file, ignore.case = TRUE)) {
# temp location
file_local <- file.path(tempdir(), basename(file))
# download the data set
download.file(file, file_local, quiet = quiet, mode = "wb")
file <- file_local
}
readRDS(file)
}
When working locally, I use the following to render rmarkdown documents:
rmarkdown::render(input = rmd.temp , output_dir = out.dir, output_file = out.name)
This gets my template doc rmd.temp, then renders the document to out.dir and names the file out.name.
I am trying to replicate on a RStudio server. When out.dir is a local directory the code works fine. However, whenout.dir is a mapped directory to an external drive, I get the following error:
Error in replayPlot(x) :
could not open file'/...path..../figure-html/unnamed-chunk-2-1.png'
The link to the mapped drive works because I can use:
dir.create(out.dir)
and see the new folder appear. Any ideas why the rendering gets stuck?
Update
This is perhaps just a permission problem because I can't write a csv file either:
df <- data.frame(a=1:10)
setwd(out.dir)
write.csv(df, file = "df.csv")
Error in file(file, ifelse(append, "a", "w")) :
cannot open the connection
RStudio server is running on Ubuntu. I will open a new question on how to give RStudio folder permissions.
For anyone who has this problem, it can be fixed by adding this to the start of your script:
Sys.umask(mode="0000")
It was a permission problem. From the shell / command line, global permission was "0000" but from the RStudio console it was "0002", which produces -rw-r-- permissions for new files. The global permission can probably be changed for RStudio but this works.