openxlsx::saveWorkbook -- write error during file append - r

I have a script that has been running smoothly for months. The last line of code basically goes as follows:
saveWorkbook(Wb, 'address/filename.xlsx'), overwrite = TRUE)
I run this script weekly (Mondays, unimportant), so I go to run it this week and I'm now getting this error when I go to save this created workbook:
Warning message:
In file.append(to[okay], from[okay]) : write error during file append
The address for this file is on a shared drive for work, so one of my first thoughts was maybe there were some new permissions for the shared drive, since saving this on local drives seems okay. But, I can save csv files on the shared drive still (using data.table::fwrite).
I'm a bit at a loss here. I've updated R, RTools, and RStudio and all my packages.
Has anyone come across this, or a similar, issue before? I could possibly be looking for some more information concerning the "write error during file append". I'm actually creating a whole new file when I run this and not appending anything to an existing file. But, I haven't been able to find anything explaining situations that could cause this error.

I have the same output but only inside a blob container on azure
overwrite instruction fails
packageVersion("openxlsx")
[1] ‘4.2.5’
> openxlsx::write.xlsx(x = mtcars,file ="mtcars.xlsx")
> openxlsx::write.xlsx(x = mtcars,file ="mtcars.xlsx")
Warning message:
In file.append(to[okay], from[okay]) : write error during file append
> openxlsx::write.xlsx(x = mtcars,file ="mtcars.xlsx",overwrite = T)
Warning message:
In file.append(to[okay], from[okay]) : write error during file append
> openxlsx::write.xlsx(x = mtcars,file ="mtcars.xlsx",overwrite = F)
Error in saveWorkbook(wb, file = file, overwrite = overwrite) :
File already exists!
Same code on my desktop produces diferent output
> packageVersion("openxlsx")
[1] ‘4.2.5’
> openxlsx::write.xlsx(x = mtcars,file ="mtcars.xlsx")
> openxlsx::write.xlsx(x = mtcars,file ="mtcars.xlsx")
> openxlsx::write.xlsx(x = mtcars,file ="mtcars.xlsx",overwrite = T)
> openxlsx::write.xlsx(x = mtcars,file ="mtcars.xlsx",overwrite = F)
Error in saveWorkbook(wb, file = file, overwrite = overwrite) :
File already exists!
As we can't fix Azure I recomend delete first and the write
> filexls= "mtcars.xlsx"
> if (file.exists(filexls)) {
+ file.remove(filexls)
+ }
[1] TRUE
> openxlsx::write.xlsx(x = mtcars,file ="mtcars.xlsx",overwrite = T)

Related

DataSpell Remote R Console Failure

First of all, I use a remote R interpreter.
When I unselect "Disable .Rprofile execution on console start" in the settings of DataSpell and save it, IDE throws a weird error when I try to start an R console as below:
CompositeException (3 nested):
------------------------------
[1]: Cannot cast org.jetbrains.plugins.notebooks.jupyter.ui.remote.JupyterRemoteTreeModelServiceVfsListener to org.jetbrains.plugins.notebooks.jupyter.remote.vfs.JupyterVFileEvent$Listener
[2]: Cannot cast org.jetbrains.plugins.notebooks.jupyter.remote.modules.JupyterRemoteEphemeralModuleManagerVfsListener to org.jetbrains.plugins.notebooks.jupyter.remote.vfs.JupyterVFileEvent$Listener
[3]: Cannot cast org.jetbrains.plugins.notebooks.jupyter.ui.remote.JupyterRemoteVfsListener to org.jetbrains.plugins.notebooks.jupyter.remote.vfs.JupyterVFileEvent$Listener
------------------------------
I tried to give an empty .Rprofile file. Nothing changed. It throws the same error. Anyway, here is my .Rprofile file:
options(java.parameters = "-Xmx4G")
options(download.file.method = "wget")
project_base <- getwd()
print(paste("getwd:", getwd()))
Sys.setenv(R_PACKRAT_CACHE_DIR = "~/.rcache")
#### -- Packrat Autoloader (version 0.7.0) -- ####
source("packrat/init.R")
#### -- End Packrat Autoloader -- ####
# These ensures that the project uses it private library
p <- .libPaths()[[1]]
Sys.setenv(R_LIBS_SITE = p)
Sys.setenv(R_LIBS_USER = p)
Sys.setenv(R_PACKRAT_DEFAULT_LIBPATHS = p)
packrat::set_opts(use.cache = TRUE)
print(paste("whoami:", system("whoami", intern = TRUE)))
print(paste("libpaths:", .libPaths()))
print(paste0("cache_path: ", packrat:::cacheLibDir()))
restore_packrat <- function(restart = FALSE) {
packrat::restore(
overwrite.dirty = TRUE, prompt = F, restart =
restart, dry.run = F
)
}
snapshot_packrat <- function() {
packrat::snapshot(
ignore.stale = TRUE, snapshot.sources = FALSE,
infer.dependencies = FALSE
)
}
I appreciate the help of anyone who faced this issue and solved it.
PS: I also issued a bug report to the developers. If you have the same problem, please upvote the issue and this question.
https://youtrack.jetbrains.com/issue/R-1393

Source multiple files in one folder in Rstudio

I have a folder with multiples R functions. I would like to source all these functions in R studio. I tried the following code, but it does not work. I found the following code here ()
sourceFolder <- function(folder, recursive = FALSE, ...)
{
files <- list.files(folder, pattern = "[.][rR]$",
full.names = TRUE, recursive = recursive)
if (!length(files))
stop(simpleError(sprintf('No R files in folder "%s"', folder)))
src <- invisible(lapply(files, source, ...))
message(sprintf('%s files sourced from folder "%s"', length(src), folder))
}
sourceFolder("C:/Users/Admin/Desktop/autots",recursive = TRUE))
However, I got this error:
> sourceFolder("C:/Users/Admin/Desktop/autots",recursive = TRUE)
Error in environment(lstar) : object 'lstar' not found
Called from: environment(lstar)
I do not know how to fix it. The package that I try to install it as a source can be found here http://stat.snu.ac.kr/heeseok/autots
Any help, please?

Download files from FTP folder using Loop

I am trying to download all the files inside FTP folder
temp <- tempfile()
destination <- "D:/test"
url <- "ftp://XX.XX.net/"
userpwd <- "USER:Password"
filenames <- getURL(url, userpwd = userpwd,ftp.use.epsv = FALSE,dirlistonly = TRUE)
filenames <- strsplit(filenames, "\r*\n")[[1]]
When I am printing "filenames" I am getting all the file names which are inside the FTP folder - correct output till here
[1] "2018-08-28-00.gz" "2018-08-28-01.gz"
[3] "2018-08-28-02.gz" "2018-08-28-03.gz"
[5] "2018-08-28-04.gz" "2018-08-28-05.gz"
[7] "2018-08-28-08.gz" "2018-08-28-09.gz"
[9] "2018-08-28-10.gz" "2018-08-28-11.gz"
[11] "2018-08-28-12.gz" "2018-08-28-13.gz"
[13] "2018-08-28-14.gz" "2018-08-28-15.gz"
[15] "2018-08-28-16.gz" "2018-08-28-17.gz"
[17] "2018-08-28-18.gz" "2018-08-28-23.gz"
for ( i in filenames ) {
download.file(paste0(url,i), paste0(destination,i), mode="w")
}
I got this error
trying URL 'ftp://XXX.net/2018-08-28-00.gz'
Error in download.file(paste0(url, i), paste0(destination, i), mode = "w") :
cannot open URL 'ftp://XXX.net/2018-08-28-00.gz'
In addition: Warning message:
In download.file(paste0(url, i), paste0(destination, i), mode = "w") :
InternetOpenUrl failed: 'The login request was denied'
I modified the code to
for ( i in filenames )
{
#download.file(paste0(url,i), paste0(destination,i), mode="w")
download.file(getURL(paste(url,filenames[i],sep=""), userpwd =
"USER:PASSWORD"), paste0(destination,i), mode="w")
}
After that, I got this error
Error in function (type, msg, asError = TRUE) : RETR response: 550
Without a minimal, complete, and verifiable example it is a challenge to directly replicate your problem. Assuming the file names don't include the URL, you'll need to combine them to access the files.
download.file() requires a file to be read, an output file, as well as additional flags regarding whether you want a binary download or not.
For example, I have data from Alberto Barradas' Pokémon Stats kaggle.com data set stored on my Github site. To download some of the files to the test subdirectory of my R Working Directory, I can use the following code:
filenames <- c("gen01.csv","gen02.csv","gen03.csv")
fileLocation <- "https://raw.githubusercontent.com/lgreski/pokemonData/master/"
# use ./ for subdirectory of current directory, end with / to work with paste0()
destination <- "./test/"
# note that these are character files, so use mode="w"
for (i in filenames){
download.file(paste0(fileLocation,i),
paste0(destination,i),
mode="w")
}
...and the output:
The paste0() function concatenates text without spaces, which allows the code to generate a fully qualified path name for the url of each source file, as well as the subdirectory where the destination file will be stored.
To illustrate what's happening with paste0() in the for() loop, we can use message() to print to the R console.
> # illustrate what paste0() does
> for (i in filenames){
+ message(paste("Source is: ",paste0(fileLocation,i)))
+ message(paste("Destination is:",paste0(destination,i)))
+ }
Source is: https://raw.githubusercontent.com/lgreski/pokemonData/master/gen01.csv
Destination is: ./test/gen01.csv
Source is: https://raw.githubusercontent.com/lgreski/pokemonData/master/gen02.csv
Destination is: ./test/gen02.csv
Source is: https://raw.githubusercontent.com/lgreski/pokemonData/master/gen03.csv
Destination is: ./test/gen03.csv
>

Not able to executing all text files from one folder by a Rscript

This is an R script for array quality metrics. The first step is going well but after the execution of the 2nd step an error occurs.
library(arrayQualityMetrics)
library(limma)
library(tcltk)
X <-tk_choose.files(caption = "Choose X")
maData<-read.maimages(X, source="agilent", other.columns = "g", green.only=TRUE)
eSet<-new("ExpressionSet", exprs = maData$other$g, annotation =maData$genes[,7])
arrayQualityMetrics(eSet, outdir="QC_C", force = TRUE, do.logtransform = TRUE)
The program is running now but it is showing this warning message:
The directory 'QC_C' has been created.
Warning messages:
1: In svgStyleAttributes(style) :
Removing non-SVG style attribute name(s): subscripts, group.number, group.value
2: In svgStyleAttributes(style) :
Removing non-SVG style attribute name(s): subscripts, group.number, group.value
Where am I getting wrong? Is this the errors in the file or the Rscript is wrong....
Give the full path of the folder under path as below:
scanFiles<-dir(path='/path/to/folder/',pattern = ".*.txt$")

Default .Options setting for unzip

I was trying to install ramnathv's slidify package and was surprised the by the following error:
# install.packages("devtools")
library(devtools)
install_github("slidify","ramnathv")
Installing github repo slidify/master from ramnathv
Downloading slidify.zip from https://github.com/ramnathv/slidify/archive/master.zip
Installing package from /tmp/RtmpOFEJuD/slidify.zip
Error in unzip(src, exdir = target, unzip = getOption("unzip")) :
'unzip' must be a single character string
I've installed it before with no issues on another system using the same Arch Linux setup and their R package, granted it was an earlier version of R (3.0.0 or 3.0.1).
In googling the error, it comes from this bit in zip.R:
unzip <-
function(zipfile, files = NULL, list = FALSE, overwrite = TRUE,
junkpaths = FALSE, exdir = ".", unzip = "internal",
setTimes = FALSE)
{
if(identical(unzip, "internal")) {
if(!list && !missing(exdir))
dir.create(exdir, showWarnings = FALSE, recursive = TRUE)
res <- .External(C_unzip, zipfile, files, exdir, list, overwrite,
junkpaths, setTimes)
if(list) {
dates <- as.POSIXct(res[[3]], "%Y-%m-%d %H:%M", tz="UTC")
data.frame(Name = res[[1]], Length = res[[2]], Date = dates,
stringsAsFactors = FALSE)
} else invisible(attr(res, "extracted"))
} else {
WINDOWS <- .Platform$OS.type == "windows"
if(!is.character(unzip) || length(unzip) != 1L || !nzchar(unzip))
stop("'unzip' must be a single character string")
...
While the default setting for unzip() is unzip = "internal", it can also be passed getOptions("unzip"):
Usage
unzip(zipfile, files = NULL, list = FALSE, overwrite = TRUE,
junkpaths = FALSE, exdir = ".", unzip = "internal",
setTimes = FALSE)
...
unzip
The method to be used. An alternative is to use getOption("unzip"),
which on a Unix-alike may be set to the path to a unzip program.
In looking at the output of .Options, I see, indeed, that there's nothing set for unzip:
> .Options$unzip
[1] ""
From perusing documentation, I see that I can set this in ~/.Renviron, but my question is whether on a Linux system this should be picked up by default or if it's pretty standard to have to set your unzip command?
If it's not standard that this be un-populated, I'll file a bug report with Arch Linux, as perhaps the package was compiled without this as a default, as documentation seems to suggest that it would be populated with an unzip command if one was found during installation:
unzip
a character string, the path of the command used for unzipping help files, or
"internal". Defaults to the value of R_UNZIPCMD, which is set in ‘etc/Renviron’
if an unzip command was found during configuration.
The Arch package I'm using is a binary and thus was pre-compiled, so intentionally or unintentionally perhaps this was overlooked or should be checked for during installation?
P.S. Just to avoid the obvious...
$ which unzip
/usr/bin/unzip

Resources