How to do a silent install of R

In this post, I’ll introduce how to do a silent install of R. Assume that you are a faculty member at an R course and need to prepare R environments for each students’ PC. In this case, you can install R, RStudio and R package in just one-click by their silent install mode.

1. R silent installation
According to the R FAQ, the R installer has command line options for silent installation “/SILENT” and “/VERYSILENT“. Download the R installer and run the command “R-3.1.0-win.exe /SILENT” from your command prompt enables you to do silent install.

p02

2. RStudio silent installation
RStudio also has silent installation option. This support page describes how to run as a silent mode. According to the page the Rstudio installer has silent option “/S” and the command “RStudio-0.98.507.exe /S” enables you to do a silent install.

p03

3. R package silent installation
R packages such as ggplot2 or plyr are installable from the command line.

3-1. Download the R packages from CRAN site
Download packages and all required/dependent packages(s) mentioned in CRAN page.

p04

3-2. Run a silent installation command
Below is an example of the command.

"%ProgramFiles%\R\R-3.1.0\bin\R" CMD INSTALL Rcpp_0.11.1.zip

p07

4. Making a silent installation script
Create a silent installation script to enable one-click installation.

4-1. Download installers and R packages and store them into the same folder
p08

4-2. Make a BAT file
Below is a code example, and save it as BAT file (ex: Rinstall.bat).

R-3.1.0-win.exe /SILENT
RStudio-0.98.507.exe /S
"%ProgramFiles%\R\R-3.1.0\bin\R" CMD INSTALL Rcpp_0.11.1.zip
"%ProgramFiles%\R\R-3.1.0\bin\R" CMD INSTALL plyr_1.8.1.zip
pause

p05

4-3. Run the BAT file as an administrator
p06

These procedures are quite simple and also available when you are updating your R environment. Let’s try when you become an R lecturer.

Posted in R

Today is my 10,000 days old birthday

I’ve been calculated my day of 10,000 days old birthday in R since few days ago.
I found that to calculate this in R is quite simple.

My birthday to 10,000 days old birthday:

> as.Date("1986-09-21") + 10000
[1] "2014-02-06"

Birthday to days since my birthday:

> Sys.Date() - as.Date("1986-09-21")
Time difference of 10000 days

Just for reference, below is an R function to convert a birthday to age.

# Birthday to age
birthday2age <- function(birthday){
  td.y <- as.integer(format.Date(Sys.Date(),"%Y"))
  td.m <- as.integer(format.Date(Sys.Date(),"%m"))
  td.d <- as.integer(format.Date(Sys.Date(),"%d"))
  bd.y <- as.integer(format.Date(birthday,"%Y"))
  bd.m <- as.integer(format.Date(birthday,"%m"))
  bd.d <- as.integer(format.Date(birthday,"%d"))
  return(td.y-bd.y-(td.m<bd.m||(td.m==bd.m&&td.d<bd.d)))
}
> birthday2age("1986-09-21")
[1] 27

cake
Happy birthday with R.

Reference:
年齢の計算は暗算でもできる

Posted in R

RForcecom – An R package provides the connection between R and Salesforce.com

In this post, I’ll introduce an R package RForcecom and its usage. As you may know, R statistical computing environment is the most populous statistical computing software, and Salesforce.com is the world’s most innovative cloud-computing based SaaS (Software-as-a-Service) CRM package.

RForcecom enables you to connect to Salesforce.com from R. It is provided as an add-on package of R and its source code are available at github.

1. Install the latest version of R
You can download the latest R statistical computing environment from the R-Project website.
http://cran.r-project.org/

2. Install and load the RForcecom
Type the commands from your R console to install and load the RForcecom.

install.packages("RForcecom")
library(RForcecom)

3. Sign in to Force.com or Salesforce.com
To sign in to the Salesforce.com, use rforcecom.login() function. Set your username, password, instance URL, API version as follows.
Note: DO NOT FORGET your security token in password field.

username <- "yourname@yourcompany.com"
password <- "YourPasswordSECURITY_TOKEN"
instanceURL <- "https://na14.salesforce.com/"
apiVersion <- "26.0"
(session <- rforcecom.login(username, password, instanceURL, apiVersion))

rforcecom-02

4. Retrieving records
To retrieve the dataset, use rforcecom.retrieve() function. Set parameters as follows.

objectName <- "Account"
fields <- c("Id", "Name", "Phone")
rforcecom.retrieve(session, objectName, fields)

rforcecom-03
rforcecom-04

5. Execute a SOQL
To retrieve the dataset using SOQL (Salesforce Object Query Language), use rforcecom.query() function. Set parameters as follows.

soqlQuery <- "SELECT Id, Name, Phone FROM Account WHERE AnnualRevenue > 50000 LIMIT 5"
rforcecom.query(session, soqlQuery)

rforcecom-05

6. Create a record
To Create a record, use rforcecom.insert() function.

objectName <- "Account"
fields <- c(Name="R Analytics Service Ltd", Phone="5555-5555-5555")
rforcecom.create(session, objectName, fields)

rforcecom-08
rforcecom-07

7. Retrieve a server timestamp
To retrieve a server timestamp from Salesforce.com server, use rforcecom.getServerTimestamp() function.

rforcecom.getServerTimestamp(session)

rforcecom-06

These procedures are very easy and are very useful for projects using R and Salesforce.com. Next post, I’ll introduce an example of a use case of RForcecom.

RForcecom website

Posted in R, Salesforce.com
about.me
Takekatsu Hiramura

Takekatsu Hiramura

Software Engineer, IT consultant and Data scientist

Categories
Follow

Get every new post delivered to your Inbox.