Error using rscript - r

I have a Homebrew version of R installed on my Mac (OS X, El Capitan 10.11.5). I've been using rscript successfully for about two weeks now. However, when I tried to run a script this morning using rscript file.r, I get the following error:
/usr/local/Cellar/r/3.3.1/R.framework/Versions/3.3/Resources/bin/R: line 209: /usr/local/Library/ENV/4.3/sed: No such file or directory
/usr/local/Cellar/r/3.3.1/R.framework/Versions/3.3/Resources/bin/R: line 209: /usr/local/Library/ENV/4.3/sed: No such file or directory
Fatal error: cannot open file '': No such file or directory
(That is the full error. Yes, it appears twice, it is not a typo.)
After getting that error, I tried uninstalling and reinstalling r with homebrew. I get the same error. The only other package that I have installed since last using rscript (to the best of my knowledge) is pspp, but I see no reason why this should have affected rscript.
Of course, the error is saying that the file /usr/local/Library/ENF/4.3/sed cannot be found. Upon inspection of /usr/local/library this is, of course, true, but I don't know what the proper way to fix this is. It seems like rscript is just trying to access sed, which comes native on OS X.
Any ideas on what I can do?
This was found to be a bug contained within Homebrew/science. The error report can be found here: https://github.com/Homebrew/homebrew-science/issues/3839
Temporary fix for this (tested on OS X, as of 07-19-2016 12:54 PM central) from ck37 on github:
mkdir /usr/local/Library/ENV
ln -s /usr/local/Library/Homebrew/shims/super/ /usr/local/Library/ENV/4.3

Instead of doing the symlinks as a temporary fix, and until the r bottle is fixed. Short answer is to brew reinstall -s r.
I posted this answer (with an explanation to why this occurs) on the duplicate question which solved this problem for me.

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!

Unable to run edit() command in RStudio

I have just started out on R and have hit a roadblock. I can't seem to run the edit() command in RStudio.
Here's what I have tried
1. Changing the RSTUDIO_WHICH_R environment variable
2. Fixing the warning messages which were displayed every time I opened the RStudio.
3. I have even reinstalled R and RStudio.
I have posted the image of the error message that I get on my Console window.
I am working on MacOS High Sierra
Any help is appreciated.
I have installed Xcode as well and the error has changed as shown in the second image.
Error Message after installing Xcode
You may be missing or have to reinstall XQuartz 2.7.11, install it first then try running edit command.If it doesn't work then do the following.(This happens sometimes during an update)
1) Find the location of libcario.2.dylib using locate command from terminal/iterm-2 . Use command locate libcario.2.dylib, you should receive something similar with this location: /usr/X11/lib/libcario.2.dylib. Someone can use cd,find to locate the location as well.
2) If the location is found then use ln -s to create a link like below:
sudo ln -s /opt/X11 /usr/X11

Passing argument to R with Command Prompt [duplicate]

I'm exploring package building on Windows 7 but have been running into trouble after reaching the Command Prompt stage. The following thread appears to be on the same topic that I'm having trouble with, but the question remains unresolved:
Cannot install R package in Windows 7
The problem: whenever I try an R CMD command in Command Prompt (e.g. I've tried R CMD install pkgName, R cmd install pkgName, Rcmd install pkgName, where pkgName is a place-holder for an actual package that has been R CMD checked on OS X and also posted on CRAN, where I have the unzipped source in the current working directory), I get the following error message:
'R' is not recognized as an internal or external command,
operable program or batch file.
(If I try the Rcmd install pkgName command, then the error starts out as 'Rcmd' is not ....) Note that even if I type in just R in Command Prompt and hit enter, I get the same error, so I'm not even able to bring up R here, though it opens perfectly fine in its stand-alone interface.
I have examined the following guides without success in identifying the trouble:
Karl W Broman's website
Rob J Hyndman's website
Steven Mosher's blog
The most immediate thing that came to mind was that the path variables in Windows were not set right, but this also has not (yet) led to the answer. For example, I have triple-checked the paths to ensure they are correct, including for the R version number, that x64 in the path name is accurate, etc.
I realize this is a complex issue to remotely diagnose, but any advice and suggestions on resolving this trouble is appreciated. For reference, below are the steps I have taken already to try to resolve this issue:
Uninstall R and Rtools
Install the latest version of R (2.15.0)
Install Rtools215 to match R version 2.15.0
Originally I let Rtools specify the path variables (turning that option on during installation). No success after this method.
I updated the path variables on my computer, where the below paths were used:
C:\Rtools\bin; C:\Program Files\R\R-2.15.0\bin\x64;
I've also tried the R CMD (and Rcmd) commands with the following paths included (note that these paths don't lead to anything on my computer, so I tried doing R CMD / Rcmd with and without them specified):
C:\Rtools\perl\bin; C:\Rtools\MinGW\bin;
Tried adding/removing the following path, which goes to the only other folder visible within the Rtools folder:
C:\Rtools\gcc-4.6.3;
Tried multiple variations of the R CMD commands, as noted earlier.
I tried this all a few months ago when I had R version 2.14.1 and Rtools214 installed, and I had the exact same trouble.
Note: I already had Cygwin installed prior to R and Rtools, and I have not installed MikTeX (yet).
Have you closed the command prompt and opened a new one after adjusting the PATH?
Enter the command PATH on the command line and ensure that you are properly updating your path
Try navigating to the directory where R.exe is saved and running it locally -- cd C:\Program...\bin\x64, R.exe.
Ensure that you're running on Windows' Command Prompt and not Cygwin's terminal
If you actually have a space after the semi-colon in your PATH, you'll need to remove that: /bin;C:/Program.... Try combining that with Joshua's solution.
I attach my whole solution here:
Install Rtools which is compatible with my R version
Add PATH: C:\Program Files\R\R-2.15.1\bin\x64;C:\Rtools\bin;C:\Rtools\gcc-4.6.3\bin
In cmd, enter: R CMD INSTALL packagename
Click "enter", done.
I had a lot of trouble getting this to work, and finally found the golden nugget on r-project (R doesn't like spaces in paths) so here's how I finally did all this:
I installed R to "c:\programs" instead of "c:\program files...". My final path to RSCRIPT.exe is "C:\Programs\R\R-2.15.2\bin\Rscript.exe"
I added that directory to my PATH, but that doesn't seem to help
RStudio is also installed under c:\Programs (e.g. c:\Programs\RStudio), but RTools is installed under the "c:\" root directory (e.g. c:\RTools).
I downloaded all the packages to "c:\downloads\r"
I opened a command prompt in "c:\downloads\r" and ran the R CMD install from this downloads directory, specifying the path to R
e.g. "C:\Programs\R\R-2.15.2\bin\x64\R CMD INSTALL colorspace_1.2-0.zip"
It appears that the CMD processor is Case Sensitive. You have to use INSTALL vs. install
Simple solution, use quotes:
c:> "C:\Program Files\WinZip\wzunzip.exe"
if you run this, you don't need to worry about the space in Program Files.
Hope this help.
I encountered a similar problem while trying to use SparkR from Windows Power Shell. Each time I would do ".\sparkR.cmd" (I was inside the folder containing this file), it would throw an error message like,
cmd is not recognized as an internal and external
command...blah...blah...blah.
I solved the problem by adding "C:\Windows\System32" to my PATH.
I restarted my system and then repeated the process and this time, I saw a new error,
R is not recognized as an internal and external
command...blah...blah...blah.
I tried all sorts of approaches, including the ones mentioned above. NOTHING WORKED, I was probably wasn't efficient enough to make it work.
Then I came across this place at code.google. I simply copied the R.bat onto a notepad, named it as R.bat. Kept it inside the folder where sparkR.cmd was located. For me it was,
C:\Apache\spark-1.5.1-bin-hadoop2.6\bin\
The I placed it on my PATH as :
C:\Apache\spark-1.5.1-bin-hadoop2.6\bin\R.bat
Restarted my laptop, opened my Power Shell as an administrator and typed :
.\R.bat help
It worked fine. Then I typed,
.\sparkR.cmd
and there it was.
It worked.
I hope it helps to people new to R. Thank you G. Grothendieck.
In the .bat file add a line of code specifying the path of the folder where R is installed and then give the path of the script as follows -
#ECHO OFF
PATH C:\Program Files\R\R-3.5.1\bin
R CMD BATCH D:\project_abc\helloworld.R
Following this, run the .bat file and you will see the code in the script will run smoothly.
In my case the issue was solved by using Edit instead of New while selecting PATH in the window below:
enter image description here
After selecting Edit I added the directory below:
C:\Program Files\R\R-4.0.2\bin\x64
This solved the issue in my case.

Rscript execution error: No such file or directory

The binary of Rscript is available but when I try to use it I get:
Rscript helloworld.r
Rscript execution error: No such file or directory
If I just do Rscript, it brings the help/usage for it through.
R CMD BATCH is working fine.
I tried adding shebang lines in the R code at the start but it didn't work.
#!/sys_apps_01/R/R-3.2.0/bin/R
#!/sys_apps_01/R/R-3.2.0/bin/Rscript
As in your case, this was caused by me moving R (in order to try to use it in an AWS lambda function).
I resorted to doing the equivalent call on R itself:
./R --slave --no-restore --file=TheScript.R
It's likely this was installed to (configured for) another directory and then moved after installation. Afterwards Rscript won't be able to find the (hardcoded?) R binary. I just had the same problem, which could be solved by reinstalling R.
Andreas
I preface this solution issuing a caution to do this at one's own risk. However I encountered the same issue and had the following solution:
Say you've run make && make install which has installed R to /path/to/install/loc. Once you've moved this to path/to/new/loc, R/Rscript will then complain it can't find the right file/directory.
Editing the R and Rscript executables in path/to/new/loc/bin, you can change any reference to /path/to/old/loc to /path/to/new/loc. This has worked for me and haven't encountered any further issues
As has been previously mentioned, it's definitely preferable to install R to the required location either through prefix=... in the configure script, or by using the rhome=... argument following make install
I encountered the same issue. What happened in my case was that, R was first installed at /usr/lib/R with deb packages, then I moved the dir to /opt/R and defined R_HOME to the new dir, hoping R will adapt to it automatically, but turns out there are hardcoded paths of /usr/lib/R in bin/R. Unless I update the paths, simply moving R to another location will break the installation.

Emacs on Mac, R, and OS X el Capitan

I use Emacs and/or Aquamacs on a Mac system to edit the R, latex, and html code. After upgrading OS X to el Capitan, R stopped working (searching for program: no such file or directory, R). I was wondering if anybody encountered the same problem and found the solution.
This is what I did and it solved the problem.
re-install R (the latest version at the time of writing this post is 3.2.4)
include (setq exec-path (cons "/usr/local/bin" exec-path)) in the .emacs.
/usr/local/bin is where the command line R is soft linked.
Of course if the R command is not found in /usr/local/bin but somewhere else, you should change the path in step 2.
I had to re-install R and all the packages after upgrading. To be able to do this step easily, save your installed packages in a file before upgrading to El Capitan. The packages have not actually been removed, they reside in
/Library/Frameworks/R.Framework/Versions/3.2/Resources/library (3.2 = version), so you can still find them, but some may be in your user library.
To save your list of packages:
my.packages = library()[[2]]
write.table(my.packages,file="my.packages.txt", row.names=F, col.names = T)
Then upgrade, re-install from R-3.2.2.pkg (or latest), then read the text file in my.packages and use install.packages(my.packages, repos='http://cran.us.r-project.org') and you should be good to go.
Regarding R under "El Capitan", you do not necessarily have to re-install it. You can find out what happened by listing the directory
ls -l /Library/SystemMigration/History/Migration-<UUID>/QuarantineRoot/usr/bin
(where <uuid> looks like 38CF2251-9593-48E9-BAA4-4880AA47E908). This is where the OS upgrade put the links that used to live in /usr/bin. Just create the same symlinks to R and Rscript as root:
cd /usr/local/bin
ln -s /Library/Frameworks/R.framework/Resources/bin/R R
ln -s /Library/Frameworks/R.framework/Resources/bin/Rscript Rscript
This assumes, of course, that /usr/local/bin is in your PATH.
New installations of R should be aware of the changes in El Capitan, cf. this R bug report.
Here is another solution: replace emacs with ``modified emacs''. It solves all the problems with Auctex (latex-preview-pane-mode) and R. It is also consistent with OS 10.11.
You can download it from: http://vgoulet.act.ulaval.ca/en/emacs/mac/
I had the same problem getting R to run on El Capitan. The problem is now solved. What follows is exacly what I tried. You might find some of the steps irrelevant but I've included them for the sake of completeness.
Tried reinstalling it via homebrew (mentioined above) and got an incompatible message concerning el capitan.
Loaded 'modified emacs' (mentioned above).
Visited the following link:
http://ftp.heanet.ie/mirrors/cran.r-project.org/bin/macosx/
then downloaded and installed:
(i) R-3.2.2.pkg
and ran the checksum command in Terminal as directed by the instructions.
(ii) XQuartz
4. Then in terminal, typed R
and it worked.
For the course I'm doing, other packages or libraries were needed. To load the package 'geonames, in Terminal type:
install.packages(c("geonames"))
A message will appear asking to select a CRAN mirror. Also another window will open with a list of mirrors, click one and OK.
Similarly, the package 'UsingR' was loaded by:
install.packages(c("UsingR"))
__end
I think the problem is that usr/bin is no longer writeable. And that's where programs like R and Rscript lived. On my system, it looks like usr/bin was moved to something like:
/Library/SystemMigration/History/Migration-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/QuarantineRoot/usr/bin
I suppose you can add that quarantined folder to your path as on my system everything seems to be working fine if executed from there.
I had the same problem. I'm not sure what's changed in El Capitan but adding the path to the R binary (/usr/local/bin on my system) to the exec-path in my .emacs file fixed the issue for me.

Resources