Skip to content

Instantly share code, notes, and snippets.

@nivertech
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nivertech/4b5b9d3da506f75f497c to your computer and use it in GitHub Desktop.
Save nivertech/4b5b9d3da506f75f497c to your computer and use it in GitHub Desktop.
Install_R.rb
## @author Zvi Avraham
## @copyright 2012-2014 ZADATA Ltd. All Rights Reserved.
define :install_R do
# Needed for RCurl CRAN package:
# sudo apt-get install libcurl4-opensll-dev
Packages = %w[
build-essential libtool m4 autoconf
fort77 r-base-dev libcurl4-openssl-dev
]
# sudo apt-get install -y ...
Packages.each do |p|
package p do
action :install
end
end
# Download R tarball
remote_file "#{Chef::Config[:file_cache_path]}/R.tar.gz" do
source node[:R][:src_link]
action :create_if_missing
end
=begin
* installing *source* package 'Rserve' ...
configure: error: R was configured without --enable-R-shlib or --enable-R-static-lib
*** Rserve requires R (shared or static) library. ***
*** Please install R library or compile R with either --enable-R-shlib ***
*** or --enable-R-static-lib support ***
=end
# TODO - needed for RStudio, but maybe will need it for integration with other packages, i.e. RPy Rcpp, etc.
# R-shlib option needed for R-Studio
#./configure --enable-R-shlib
# compile without X / GUI
#./configure --with-x=no
# Compile and install R
bash "install_R" do
cwd Chef::Config[:file_cache_path]
code <<-EOH
set -e
tar xzf R.tar.gz
cd R-*/
./configure --with-x=no --enable-R-shlib
make
sudo make install
EOH
#creates "/usr/local/lib/R/lib/libR.so"
creates "/usr/local/bin/R"
end
# http://www.rforge.net/Rserve/doc.html
# https://github.com/nivertech/common/wiki/Erlang-Rserv
# TODO : Add to upstart:
# sudo R CMD Rserve
# See:
# http://stackoverflow.com/questions/7075709/install-binary-zipped-r-package-via-command-line
# Rscript -e "install.packages('foo.zip', repos = NULL)"
# Rscript -e 'install.packages(pkgs='bitops', repos="http://cran.r-project.org")'
# sudo Rscript -e 'install.packages(pkgs=c("Rserve","bitops","RCurl","RJSONIO"), repos="http://cran.r-project.org")'
# Calculate string like this:
# sudo R CMD INSTALL Rserve.tar.gz RCurl.tar.gz RJSONIO.tar.gz
# Explicitly download R packages and install them
if !node[:R][:lib].nil? && !node[:R][:lib].empty?
# download packages
node[:R][:lib].each do |lib, src_url|
remote_file "#{Chef::Config[:file_cache_path]}/#{lib}.tar.gz" do
source src_url
action :create_if_missing
end
end
libs = node[:R][:lib].keys.map {|lib| "#{lib}.tar.gz"}.join(' ')
bash "install_R_libraries" do
cwd Chef::Config[:file_cache_path]
code <<-EOH
sudo R CMD INSTALL #{libs}
EOH
end
end
# Automatically find and download R packages in repos (CRAN, etc.)
repos = node[:R][:repos]
pkgs = node[:R][:pkgs]
if !pkgs.nil? && !pkgs.empty? &&
!repos.nil? && !repos.empty?
pkgs2 = pkgs.map {|p| "\"#{p}\""}.join(',')
repos2 = repos.map {|r| "\"#{r}\""}.join(',')
bash "install_R_packages" do
cwd Chef::Config[:file_cache_path]
code <<-EOH
sudo Rscript -e 'install.packages(pkgs=c(#{pkgs2}), repos=c(#{repos2}))'
EOH
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment