Emacs on Mac, R, and OS X el Capitan - r

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.

Related

Building Tools are missing in RStudio

First of all, I am working on a Mac. I am trying to install Blotter from GitHub. I found several descriptions of how to do that but my RStudio tells me that I am missing Building tools and gives me a link (https://www.cnet.com/how-to/install-command-line-developer-tools-in-os-x/) where it is described to do that. So far so good. I downloaded Xcode and the command line tools for Mac and installed those. Nothing changed even after restarting R. Then I found this https://cran.r-project.org/bin/macosx/tools/. I installed it and during that, it told me that I had to do the following
"This package will install clang 6.0.0 for OS X 10.11 (El Capitan) or higher with OpenMP support in /usr/local/clang6
In order to use this compiler you have to add /usr/local/clang6/bin to the PATH environment variable such as
export PATH=/usr/local/clang6/bin:$PATH"
So I changed the environmental variable path as follows http://blog.tonytsai.name/blog/2018-05-07-setting-path-variable-for-gs-command-in-rstudio/.
How I changed the PATH variable.
Again I restarted R but still, nothing changed. I still get the notice that the building tool is missing.
Somehow it seems to me that I installed everything correctly but R doesn't recognize the Programmes. Does anyone have an idea? I tried to search for settings to tell R that I installed the command line tool but couldn't really find anything helpful.
Ok, a bit of an update.
Best I can see it that Blotter is built and stored on R-Forge packages under a package called RStrategist
In R console type/cut & paste this.
install.packages('RStrategist',repos='http://R-Forge.r-project.org')
See R forR-Forge for more details. Once this has been installed run instead.
library(RStrategist)
Unfortunately, I am not willing to install this package and see if it works mainly because 1) don't need it nor know how to use it, 2) not sure how good packages are from R-forge, though it seems legit, but, this brings me back to point one.
So before i read the updated answer of Conrad Thiele i was trying around bit. Basically i deleted R, R Studio, Xcode and Command Line tools. Then i installed Xcode, Command Line tools, R and RStudio. Then i followed the notice on https://cran.r-project.org about the tools and installed both stated tools. As mentioned in the original question the Clang package tells you to change the Environmental Variable. And there was the mistake i believe. I originally simply pasted "PATH=/usr/local/clang6/bin:$PATH" into the the ".Renviron" file. With reading up online i noticed that "export PATH=/usr/local/clang6/bin:$PATH" is actually a Command for the Mac Terminal. After executing it, it sill didn't work but then i remembered that i still had the Path "PATH=/usr/local/clang6/bin:$PATH" in the the ".Renviron" file. Once i deleted that it worked. So i guess the key was that with changing the Environmental Variable correctly R found the connection with the right tool. Patients paid off.

Running R from Mac OSX terminal

I've searched the web, and I'm still unclear on how to run R from the Mac terminal. I have Rstudio and the standalone R app installed. I thought I could just type "R" from the command line as I do with "python", but that doesn't work. Is it necessary to edit the PATH in my bash profile? If so, how do I give the correct location of R?
Thanks for any help
Edits after receiving comments
So, I'm running Sierra, and when I type "r" or "R" at the terminal, I get "-bash: R: command not found." If I type, "which R" in the terminal I do not get any output.
Here is the output from "echo $PATH": /usr/local/heroku/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/samuelcolon/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Users/samuelcolon/.rvm/gems/ruby-2.1.0/bin:/Users/samuelcolon/.rvm/gems/ruby-2.1.0#global/bin:/Users/samuelcolon/.rvm/rubies/ruby-2.1.0/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/samuelcolon/.rvm/bin:/Users/samuelcolon/.rvm/bin
As for the installation, I believe I downloaded it directly from cran.r-project.org a while ago. I can locate the GUI in my applications and open it--
I have version 3.13. Is it possible, I only have R.app installed but not R? Perhaps that's the reason I'm getting the 'command not found' when typing "R" into the terminal?
Generally, I've been working in RStudio, but I'd still like to access R from the terminal and also to find where things are located. I'm fine with removing and re-installing R if it's easiest to start from square one. I hope the extra detail helps, and I appreciate the responses.
An answer for those not that familiar with Terminal and Bash.
I have done a fresh update install of R from the R.org cran site as part of seeking an answer to your question.
I found this latest install version 3.4.0 installs R for access in Terminal, and also installs R.app as part of the package.
To my understanding, reading support docs, if you have an older version of R it will update that. However it will not update an installation of R installed by the anaconda package.
Where are the R files stored?
I can only assume that with a fresh install of the latest R, R will work for you in Terminal.
To learn where the R files are that are being accessed - in Terminal after starting R, and in R.app, type:
>R.home()
In my case as example:
In R.app - the R version 3.4.0 is accessed in the top directory (not my user folder):
R.home()
[1] "/Library/Frameworks/R.framework/Resources"
In Terminal - the R version 3.3.2 is accessed in the Anaconda package, again in the top level directory.
R.home()
[1] "/anaconda/lib/R"
So I have two different versions of R, and Terminal accesses a different version to R.app.
How can I ensure I access the same version in Terminal as I do in the R.app?
For someone familiar with bash, and how the whole bash command system works I am sure there is a well constructed command. All the same here are some novice solutions.
-
• First Solution:
I could update the anaconda version, however, I would prefer not to as as other elements of the anaconda package my depend on this older version of R. For those not yet familiar with Terminal and bash, not such a novice solution.
-
• Second Solution:
This solution came from mko. It provides a single use solution. From the result above, and checking the directory structure a little further to find this R file.
Finding the significant R file enables me to edit an extension of the above path shown in the R.app. So add /bin/R to enter
/Library/Frameworks/R.framework/Resources/bin/R
Entering and pressing return will start R from this version.
Alternatively, one can find this file and icon in the GUI Finder, lead by the above result, and just double click on it, and it will open Terminal and a session with R running for you. Easy!
One could also make an alias of it and put it on your desktop for easy future starts.
-
• Third Solution:
My last solution I think may be best, adding to mko's solution. Make an alias.
Being in my home directory in Terminal I open .bash_profile using the nano text editor. (If you do not already know how to do this, then best not use this solution.)
I then add the line in this env file.
alias Rv340='/Library/Frameworks/R.framework/Resources/bin/R'
I then save the changes and exit this terminal session. I then open a new Terminal window. (This is so the changes to the env above are incorporated in the new terminal session).
Then when I enter the alias:
Rv340
The version of R I want opens.
You can choose a different alias name to "Rv340".
-
• Fourth Solution:
A second more permanent solution for opening the same version of R in Terminal is as follows.
Copy the path as showing in R.app in response to the R.home() command above, and add that path to PATH in your .bash_profile. (If you do not know already how to do this, then ignore this solution.) Do so as follows.
export PATH="/Library/Frameworks/R.framework/Resources:$PATH"
To my understanding, this ensures that bash looks here for R (and anything else), then moves on to the other paths in PATH. Since this adds this path to the beginning of $PATH, an env variable, bash looks here first where it finds the newer version first, and stops looking.
When it comes to understanding PATH in the env set up in .bash_profile the following two links were helpful.
About PATH.
How to correctly add a path to PATH.
This solution may muck with anaconda's invocation of R. I have yet to check this.
First of all, you have to start terminal application. You can use either built in Terminal.app, or you can use replacement. My favorite one is iTerm2
https://www.iterm2.com
Then, you simply open terminal window and run R. Just like shown below:
Have fun with R!
Just ran into the same issue when installing R-4.0.3.pkg on my MacBook (MacOS BigSur). Can open R.app to the clunky R GUI, but typing in 'R' in terminal doesn't work.
Turns out, an R executable lives here: /Library/Frameworks/R.framework/Versions/4.0/Resources/bin/R
So I added this alias to my newly created .zshrc script:
alias R '/Library/Frameworks/R.framework/Versions/4.0/Resources/bin/R'
Now when I type in R, it opens... I swear this all happened seamlessly in earlier versions.
There is currently a bug in CRAN's R installation package that results in it not correctly installing symbolic links to R and Rscript for commandline use. I've just verified this by inspecting the postflight script in their 4.0.5 installation package. This only impacts MacOS system releases of 20 and above (you can check with uname -r).
I've included more info here, along with what the "correct" fix should be: manually creating symbolic links to /usr/local/bin that point to the R and Rscript binaries themselves. If this is the current challenge, then this would be a far better solution to creating aliases or manipulating PATH in various ways, since it's what the installation package intended to do (and presumably will again soon).
R: command not found
In short, if this is the problem, then Ashkan Mirzaee's answer (https://stackoverflow.com/a/67202173/2093929) to create the symbolic links directly is correct in form, but might not have the right link command. The 4.0.5 package intends instead to use:
mkdir -p /usr/local/bin
cd /usr/local/bin
rm -f R Rscript
ln -s /Library/Frameworks/R.framework/Resources/bin/R .
ln -s /Library/Frameworks/R.framework/Resources/bin/Rscript .
You can create a symbolic link from R and Rscript binaries to /usr/local/bin to add them to the PATH:
sudo ln -s /Library/Frameworks/R.framework/Versions/Current/Resources/bin/R /usr/local/bin
sudo ln -s /Library/Frameworks/R.framework/Versions/Current/Resources/bin/Rscript /usr/local/bin
Now which R should return /usr/local/bin/R and you can use R.
An easy way to open RStudio with admin privilege on macOS:
Go to Applications, then right click on RStudio
Select "Show Package Contents"
Go to Contents/MacOS
Now open terminal(in bash mode). Type sudo and drag the RStudio.exec into terminal and press on ENTER
Now RStudio will have admin access!

how to install RODBC on macOS Sierra 10.12.4

In R 3.4.0,
install.packages('RODBC', type='source')
fails on macOS 10.12.4. I also downloaded RODBC_1.3-15.tar.gz from CRAN and tried,
R CMD INSTALL RODBC_1.3-15.tar.gz
In both cases, I got "ODBC headers sql.h and sqlext.h not found". A discussion of this in Installation of RODBC/ROracle packages on OS X Mavericks says the following:
To fix this, you need to download the latest version of iODBC (www.iodbc.org), and then unzip the file and set your header and library search paths to the location where you put the unzipped package. If you don't know how to set your search paths, you could just put the header files (sql.h and sqlext.h) in the /usr/include directory, and the libiodbc.a file in the /usr/lib directory.
I downloaded iodbc-42.5.tar.gz and untarred it into a directory next to RODBC, untarred from RODBC_1.3-15.tar.gz. Sadly, I can't find how to set header and library search paths, and when I try to put the header files in /usr/include, the system won't let me.
iodbc-42.5/iodbc/README.MACOSX says,
You first need to install the latest Mac OS X Developer Packages, which can be found at http://developer.apple.com/tools
I think I've done that, but I don't know how to check it. [In fact, I think I've done it multiple times: The message ODBC headers sql.h and sqlext.h not found, disappeared for a while from the still-negative response to install.packages('RODBC', type='source'), only to reappear later after I successfully installed port and ran sudo port install gcc6. Then I got ODBC headers sql.h and sqlext.h not found again.]
iodbc-42.5/iodbc/README.MACOSX continues,
Then, you can open the Xcode Project Builder files under mac/iODBCinst, mac/iODBC, mac/iODBCtest and mac/iODBCtestw.
I don't know how find any of these. It further continues,
or execute the following commands from a terminal session to build all the frameworks and demo applications:
$ cd mac
$ make
I did $ cd mac and got -bash: cd: mac: No such file or directory. Evidently, I need to substitute something for mac here, but I don't know what. ???
Thanks.
I solved the problem with:
ODBC_INCLUDE=/path/to/libiodbc-srcs/include R CMD INSTALL RODBC
where "/path/to/libiodbc-srcs/include" is the path to the "include" folder containing the missing files, "sql.h" and "sqlext.h". In my case it was something like '~/Documents/Rstuff/iodbc-42.5/iodbc/include', which I checked with the following in R:
dir('~/Documents/current/Rstuff/iodbc-42.5/iodbc/include')
Then the following worked for me:
ODBC_INCLUDE=~/Documents/current/Rstuff/iodbc-42.5/iodbc/include R CMD INSTALL RODBC
This is described in p. 19 of https://cran.r-project.org/web/packages/RODBC/vignettes/RODBC.pdf, except that contains a stray quote (<'>), which threw me off the first few times I read it, because was not familiar with that syntax.
On R-Sig-Mac, Marc Schwartz offered two suggestions: First, Installation of RODBC on OS X Yosemite, which may work with "brew"; I didn't try that, because I got the above to work first.
Second:
install.packages("RODBC", type = "source",
configure.args = "--with-odbc-include=/path/to/libiodbc-srcs/include/")
This should work also with the path substitution mentioned above.
I hope this helps someone else.

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.

Error using rscript

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.

Resources