Skip to content

Instantly share code, notes, and snippets.

@sethwalker
Last active December 22, 2015 21:09
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 sethwalker/6531536 to your computer and use it in GitHub Desktop.
Save sethwalker/6531536 to your computer and use it in GitHub Desktop.
quick and dirty chef helper for installing packages from CRAN
# modified from http://stevendanna.github.io/blog/2011/12/26/snow-and-chef/
module CranHelper
def self.r_package_is_installed(package_name)
r_code = "if (any(installed.packages()[,1] == '#{package_name}')) { quit('no', 0, FALSE) }; quit('no', 1, FALSE)"
"echo \"#{r_code}\" | R --no-save --no-restore -q"
end
def self.r_package_install(package_name)
r_code = "install.packages('#{package_name}')"
"echo \"#{r_code}\" | R --no-save --no-restore -q"
end
end
execute "install RJSONIO from CRAN" do
command CranHelper.r_package_install("RJSONIO")
not_if CranHelper.r_package_is_installed("RJSONIO")
end
file "/home/ubuntu/.Rprofile" do
owner "ubuntu"
group "ubuntu"
mode "0644"
action :create_if_missing
content 'options("repos"="http://cran.us.r-project.org")'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment