Wednesday, January 23, 2008

R from ruby

rsruby lets you run supposedly any function in R from ruby.

Elaborating on the sci-ruby page
sudo apt-get install r-base ruby1.9.1-full ruby1.9.1-dev
sudo ln -s /usr/lib/R/lib/ /usr/lib/
sudo ln -s /usr/share/R/include/R.h /usr/include/R.h
gem install rsruby -- --with-R-dir=/usr/share/R

I thought this was necessary, but don't so much any more:
# add a line to your .bashrc file to point to R:
echo "export R_HOME=/usr/lib/R" >> ~/.bashrc
source ~/.bashrc   # read the bashrc file to get the variable


Eldon said...

Were I competent in R and interested in learning Ruby where would I start?

EP said...

Are we supposed to add the "echo" line to our .bashrc file? Something like:
sudo gedit .bashrc

And then go to the bottom and add the echo line?

And the "source" line, do you enter that into the terminal, or command center in my case?


JTP said...

yes, but not with the echo stuff.

echo "whatever" >> whateverfile

'echo' -> print (send to STDOUT)
'>>' -> append to the file

These are very, very handy for manipulating files in linux. Basically, if you copy and paste that echo line into your terminal as is, it will save you the step of having to open an editor and type in the line. Of course, at some point you will want to open up your .bashrc and play around with things. This is where you can set up your whole environment.

adding a line of code to a document (.bashrc) file does not mean it is read. Basically, the .bashrc file is read every time you open up your command center. So, if you want something permanent in your computing environment, a great place to put it is in your .bashrc file. However, after adding the variable (or whatever) to your file, you either need to A) open a new terminal (which will then cause your .bashrc file to be read) or B) read your .bashrc from the terminal that you are in. The way you read files from within bash is to say: source <whatever_file>

EP said...

Any ideas why when I enter in your last line of code "sudo gem..." I get:
sudo: gem: command not found

JTP said...

you need to install ruby gems (google rubygems download) and download it and install it.