Error while exporting zipped files from R linux server - r

I get the following R code execution error when I try to export and download zipped files from the R Linux server to my computer even though I have the zip and unzip files installed.
Error in system(createZipCommand, intern = TRUE) :
error in running command
Have anyone come across something similar and how did you solve it?
many Thanks
RJ

I think I figured out what's going on here. It appears that the PATH definition (echo $PATH) got corrupted. This was also preventing me from installing and updating packages.
I updated the path-definition in the '.Renviron' file as below
PATH=/usr/lib64/ccache:/usr/lib/rstudio-server/bin/postback:/usr/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/puppetlabs/bin
Saved this new '.Reviron' file in the home folder, logged off from R Studio, and signed back in. Everything seems to be fine now.

Related

Can I change the location of Homebrew FFTW install? R can't seem to read FFTW3.h file located in Cellar folder

I'm trying to install wholebrain by Daniel Fürth, following the instructions on the macosX install page (available here). I am running MacOS Big Sur 11.5.2, R 4.1.2, and RStudio 2021.09.1.
Unfortunately, the program is not straight-forward to install and requires significant developer tools to work correctly. I'm not a programmer and have almost no experience with coding, so I've been mucking through the instructions for two days now trying to get the install to work correctly and I'm firmly stuck on the final step.
In RS, when I run, devtools::install_github("tractatus/wholebrain", INSTALL_opts=c("--no-multiarch")) I get the following error message:
/bin/sh: pkg-config: command not found filter.cpp:9:10: fatal error: 'fftw3.h' file not found #include "fftw3.h" ^~~~~~~~~ 1 error generated. make: *** [filter.o] Error 1 ERROR: compilation failed for package ‘wholebrain’
I have been trying to figure out what this means for quite awhile now and I think I've narrowed it down to R is not reading the location of the fftw header file from where it was installed by Homebrew. (I could be totally wrong, again- not a programmer)
From what I understand, Homebrew always installs under opt/homebrew/cellar. And, in fact, in there is the compiled fftw program with the needed "fftw3.h" file. But for some reason, RStudio is not able to find and read the file in that location.
From random googling and reading of other posted issues, I think that RStudio may expect the file to be under usr/local/include. Can I just copy and paste the header file into that folder? Or will I be screwing something up if I do that? I am totally intimidated by fftw's description of manual compilation so I don't really want to attempt that. Is there a way to change where R is looking for that header file? I already set my wd to "/" so shouldn't R be able to access any folder on my computer?
I want to post an answer here for anyone who comes after me with the same issue. It came down to RStudio not recognizing the programs Homebrew had installed because it wasn't reading the file location where Homebrew saves them. Homebrew always installs programs in /opt/homebrew/... Here is what I had to do:
In RStudio, open your Renviron file using this command: usethis::edit_r_environ()
In the file that opens (which for me was totally blank), type: PATH=/opt/homebrew/bin:${PATH}, or whatever your particular path you want prepended to the Renviron path is.
Quit RStudio and, when prompted, save. Re-open RStudio and run Sys.getenv("PATH") to check. Your new path (in the example above, '/opt/homebrew/bin') should now be prepended to the list of paths that RStudio will use when looking for programs/files. For me this now looks like /opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Library/Apple/usr/bin:/Applications/RStudio.app/Contents/MacOS/postback
Finally, I want to say thank you very much to Mark Setchell who really helped point me in the correct direction!

How to fix Error in setwd("D:/") when opening R

I'm currently trying to Knit a file with RStudio and keep running into the below error:
Error in setwd("D:/") : cannot change working directory
Execution halted
However, when I check getwd() I get "/Users/my-name" as the working directory. I have also tried setwd("~/") and receive the same error in Markdown. Further, when I initially open RStudio I get
Error in setwd("D:/") : cannot change working directory
which suggests that there is an issue when I start R. Is there a way to get this error to stop from occurring when starting RStudio in the first place? I've tried deleting and redownloading RStudio but that doesn't seem to work. I'm currently using Mac OS Catalina.
Below is a screenshot of the error I receive when I open RStudio.
Thanks in advance.
I got similar issue with "setwd". When I did "save as" my existing code file from other folder to a new folder then I got an error: "cannot change working directory". When I did copy a code file from other folder and paste it into a new folder then I was able to run "setwd" and there was no error.

What's the reason that readRDS doesn't seem to work in Windows?

I'm trying to make the my code portable to Windows and realized that even though I use file.path to create paths still the readRDS function won't work, for example:
file.exists('C:/temp/HarvardX-Skillability/data/rds/Users.rds')
> TRUE
readRDS('C:/temp/HarvardX-Skillability/data/rds/Users.rds')
> Error in readRDS("C:/temp/HarvardX-Skillability/data/rds/Users.rds") :
error reading from connection
I also tried:
file.exists('data/rds/Users.rds')
> TRUE
readRDS('data/rds/Users.rds')
> Error in readRDS("data/rds/Users.rds") : error reading from connection
Why is that? and how can I fix it? In Ubuntu 18.04 works perfectly ...
The problem seems to be with downloading/cloning the files from GitHub. After running git clone on your repository, when I open my local copy of Tags.rds in a text editor I see this:
version https://git-lfs.github.com/spec/v1
oid sha256:b4a2cb3775126a3895e9533ef9ef4ad786b2021cfd1660b07028fbef85b025bb
size 641098
(this is the entire contents of the file). Furthermore, running file Tags.rds (in a Terminal on MacOS) reports Tags.rds: ASCII text. (All of the .rds files are like this.)
The GitHub web interface confirms that your files are OK on the repo:
This question looks related. After installing Git LFS and running git lfs pull, I get the full file downloaded (and readRDS() seems to work fine).
The culprit to the OP was something really unexpected, I also didn't provide the information for it because I couldn't suspect this was the issue.
The problem was those files were being downloaded automatically using download.file(url, filePath, extra="L") and in Windows this is known to cause issues with binary files that are not the expected ones. This is why the rds files were unrecognizable.
I found out while building exception handling recovery code that was looking to download the same files from a Dropbox folder and then came to the same issue, therefore it wasn't because of Git LFS.
The OP solution was to add the argument download.file(..., mode="wb").
See the question R trouble unzipping file under Windows

Issue: Working Directory in R Studio "stuck" on directory containing open R Markdown file

I am using the most recent version of R (3.3.2), running in the most recent version of RStudio (1.0.136) on MacOS Sierra (10.12.3). I am running into an issue in which my working directory corresponds, and is stuck on, the directory that contains the .RMD file I currently have open in RStudio. Upon opening the file, the working directory is correctly set to the directory holding the .Rproj file. When I go to load in a file with a path relative to that directory, however, I get an error that there is no such file in the current working directory, and the error returns the location of the .RMD file as that working directory.
The working directory, however (using getwd()) still reads where the working directory is supposed to be, and no matter where I try to set it, I still get the same error message when I try to read in a file. Notably, I do NOT get an error message that the working directory cannot be changed--R tells me that the working directory has been changed, and that directory is allegedly the current working directory...but it's not.
I have tried fully (as far as I am aware) uninstalling R and R studio and reinstalling them, to no avail. Does anyone have a solution? This is frustrating the heck out of me right now, since I have to revise all the relative paths in the notebooks that I have defined to do my work in the interim.
Extra information in case it's relevant: I restored from a Time Machine backup that I suspect may have been corrupted somehow; some contents of my Applications folder were missing that I had to move over manually. Could this be causing the issue? Are there other system files that R depends on when interacting with the filesystem that I might look to? I'm trying to avoid doing a clean OS install or a piecemeal rebuilding of my files, since I don't know if that's actually the issue.
Thanks in advance!
This is a known feature/bug of RStudio notebooks (Working Directory about halfway down). Notebooks are executed in the same directory as the file. As #Simon Jackson noted, you can change this using knitr::opts_knit$set(root.dir = normalizePath()).

unzip() fails using install_github

A number of people in my team are having issues installing packages from Github using install_github on Windows 7 Enterprise. However, I do not have these issues on the same build. For example, when trying to install readr, they see the following:
> devtools::install_github("hadley/readr")
Using GitHub PAT from envvar GITHUB_PAT
Downloading GitHub repo hadley/readr#master
from URL https://api.github.com/repos/hadley/readr/zipball/master
Error in utils::unzip(src, exdir = target) :
cannot open file 'C:/Users/XXXXX/AppData/Local/Temp/RtmpYVS4zi/devtools23d42e596b7c/tidyverse-readr-b8c3ddb/R/POSIXct.R': No such file or directory
They have write access to the TMP folder into which these files are being extracted.
Interestingly enough when they download the zip directly from Github's website and try to extract into their user folder, they get the same behaviour from Winzip, but 7-zip can successfully unpack the file.
Does anyone know what might be causing this behaviour?
Try running
options(unzip = "internal")
before running devtools::install_github.
This has worked for me in the past, not sure why.

Resources