Run JGR for R in Ubuntu 14.04 directly - r

I recently installed Ubuntu 14.04.2 LTS (trusty) and followed the instructions on http://r-interface.blogspot.nl/2012/04/install-r-jgr-and-deducer-in-ubuntu.html to install R, JGR and deducer.
If I run R, load JGR and open JGR from there, it works, but I like to create a shortcut directly to JGR. I tried simply locking the JGR console to the launcher, but if I then click on it, it will mention:
'Unable to start R: Unable to initialize R'.
In the above mentioned link, at step 4 I managed to create the desktop icon which should link to /usr/local/lib/R/site-library/JGR/scripts/run, but when I open that in the files browser, nothing happens. JGR also turns up empty when in the applications.
Anyone know how to do this?

I faced the same situation but it could be solved manually.
follow the same guide http://r-interface.blogspot.com.es/2012/04/install-r-jgr-and-deducer-in-ubuntu.html up to the point 4
in the point 4 , with R launched ( sudo R --no-save )
library(JGR)
JGR()
note that it prints in the screen the contents of a bash script. Something like (but use yours):
#!/bin/sh
export R_HOME="/usr/lib/R"
export R_ARCH=""
export R_LIBS="/home/jesus/R/x86_64-pc-linux-gnu-library/3.0:/usr/local/lib/R/site-library:/usr/lib/R/site-library:/usr/lib/R/library"
export R_LIBS_USER="~/R/x86_64-pc-linux-gnu-library/3.0"
export JAVA_LD_PATH="/usr/lib/R/lib:/usr/lib/x86_64-linux-gnu:/usr/lib/jvm/java-7-oracle/jre/lib/amd64/server:#JAVA_LD#"
'/usr/lib/jvm/java-7-oracle/jre/bin/java' -cp '/home/jesus/R/x86_64-pc-linux-gnu-library/3.0/rJava/java/boot' -Drjava.class.path='/home/jesus/R/x86_64-pc-linux-gnu-library/3.0/rJava/jri/JRI.jar:/home/jesus/R/x86_64-pc-linux-gnu-library/3.0/iplots/java/iplots.jar:/home/jesus/R/x86_64-pc-linux-gnu-library/3.0/JGR/java/JGR.jar:/usr/lib/R/etc/classes:/usr/lib/R/etc/classes/classes.jar' -Drjava.path='/home/jesus/R/x86_64-pc-linux-gnu-library/3.0/rJava' -Dmain.class=org.rosuda.JGR.JGR -Djgr.load.pkgs=yes -Dr.arch= RJavaClassLoader
You only need to create the missing file /usr/local/lib/R/site-library/JGR/scripts/run (use the same name than in the guide, or adjust at your will) with the contents spat in the previous step.
Make it executable :
chmod a+x /usr/local/lib/R/site-library/JGR/scripts/run
Continue the guide where you leave the step 4

Related

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

run R as administrator

I was using my own laptop to install R and I found that it only has one library. Evne though this library is still read only, everytime when I use Rstudio: install.packages("abc"), I can see that the new packages are stored automatically into that read only library folder.
In my office's desktop, I "believe" I also have administrator role, as I can install and remove anything (by far). I download the latest version of R and I right click the R-3.4.1-win.exe, there is an item "run as administrator", then it is installed in my desktop. However, when I use R studio to install new packages as in my laptop, it always automatically create a personal folder to store the new packages. I don't know why. Is that a way to only have one folder for library? I also tried on the desktop in the plain R mode (without using Rstudio). When I want to install new packages, it always says
Warning in install.packages("devtools") :
'lib = "C:/Program Files/R/R-3.4.1/library"' is not writable
And there is a window pops up to ask me "would you like to create a personal folder?" And if I say no, then
Error in install.packages("devtools") : unable to install packages.
Is there a ways to solve this problem? To just maintain one folder for library
What version of Windows are you using? You should be able to right-click on the Rstudio.exe icon, click Properties, and select an option to always run Rstudio as administrator. Be sure you use that same icon whenever you want to open Rstudio.
Incase of Mac, go to Applications, then right click on RStudio and
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!
For completeness, I think there should be an Ubuntu answer to go along with the Microsoft and Apple answers. (Note:I'm using 18.06, and not 20.x.)
What doesn't work:
On my Ubuntu/Linux system, when Rstudio is installed the call start RStudio from a terminal looks something like the following:
(base) username#sysname:~$ rstudio
It starts, but has the permissions of the user, and can have access errors.
What gives admin power:
To give it better permissions, you can use sudo.
(base) username#sysname:~$ sudo rstudio
[sudo] password for username: <enter password here>
It starts in a different user location, but has more power. After it is installed you can run it the regular way and the packages are still installed.
Extra credit:
Here are some (currently) relevant links for RStudio on Ubuntu:
https://linuxhint.com/rstudio-for-ubuntu/
https://www.r-bloggers.com/2013/03/download-and-install-r-in-ubuntu/
What is the command to invoke RStudio from Command Line in linux environment?
http://web.cs.ucla.edu/~gulzar/rstudio/index.html

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!

Installing Python modules

I am trying to install the pyperclip module for Python 3.6 on Windows (32 bit). I have looked at various documentations (Python documentation, pypi.python.org and online courses) and they all said the same thing.
1) Install and update pip
I downloaded get-pip.py from python.org and it ran immediately, so pip should be updated.
2) Use the command python -m pip install SomePackage
Okay here is where I'm having issues. Everywhere says to run this in the command line, or doesn't specify a place to run it.
I ran this in the command prompt: python -m pip install pyperclip. But I got the error message "'python' is not recognized as an internal or external command, operable program or batch file.
If I run it in Python 3.6, it says pip is an invalid syntax. Running it in IDLE gives me the same message.
I have no idea where else to run it. I have the pyperclip module in my python folder. It looks like a really simple problem, but I have been stuck on this for ages!
You need to add the location of the python.exe to your $PATH variable. This depends on your installation location. In my case it is C:\Anaconda3. The default is C:\Python as far as I know.
To edit your path variable you can do the following thing. Go to your Control Panel then search for system. You should see something like: "Edit the system environment variables". Click on this and then click on environment variables in the panel that opened. There you have a list of system variables. You should now look for the Path variable. Now click edit and add the Python path at the end. Make sure that you added a semicolon before adding the path to not mess with your previous configuration.

RStudio not reading system variables when started via launcher

I'm having a few problems with system environment variables with RStudio. In ~/.bashrc some custom environment variables are set which I want to access in my program using Sys.getenv().
When I'm calling Rstudio from the command line, this works fine. However, when I'm using the Ubuntu launch function (Alt+F2) to start RStudio, my environment variables are not found. For portability, I would kind of prefer for this to work, too...
Can someone help?
You need to find Rstudio's desktop launcher. In Ubuntu, launchers are simple text files with the extension .desktop. You can read more about the file format here. The most common locations for these are /home/user/.local/share/applications (user-specific) and /usr/local/share/applications (system-wide). The easiest way to edit these files is to use an app called menulibre.
You can install menulibre by running the following command in the terminal:
sudo apt-get update && sudo apt-get install menulibre
You can then use menulibre to find and edit the Rstudio launcher.
I have just tried using Sys.getenv() on my Rstudio installation, and it works fine. My Rstudio launcher command is /usr/lib/rstudio/bin/rstudio %F
Edit: I am running Rstudio Version 0.99.491

Resources