R package installation on a shared server

Installing Packages

May 12, 2016

Check

Some packages may already be installed, so try loading them first:

require(ggplot2)
## Loading required package: ggplot2
require(RODBC)
## Loading required package: RODBC
## Warning in library(package, lib.loc = lib.loc, character.only = TRUE,
## logical.return = TRUE, : there is no package called 'RODBC'

Install

Check your paths:

.libPaths()
## [1] "C:/Users/Jeremy/Documents/R/win-library/3.2"
## [2] "C:/Program Files/R/R-3.2.4revised/library"
Sys.getenv("R_LIBS_USER")
## [1] "C:/Users/Jeremy/Documents/R/win-library/3.2"
.libPaths(c(Sys.getenv("R_LIBS_USER"), .libPaths())) # Add your user library to R's package search path
install.packages("RODBC", lib = .Library)
install.packages("RODBC", lib = Sys.getenv("R_LIBS_USER"))

Installing packages to a custom folder

.libPaths(c(.libPaths(), "C:\\Users\\Jeremy\\test-library"))
install.packages("RODBC", lib = .libPaths()[3])

SQL Queries On Data Frames

##   Sepal.Length    Sepal.Width     Petal.Length    Petal.Width   
##  Min.   :4.300   Min.   :2.000   Min.   :1.000   Min.   :0.100  
##  1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600   1st Qu.:0.300  
##  Median :5.800   Median :3.000   Median :4.350   Median :1.300  
##  Mean   :5.843   Mean   :3.057   Mean   :3.758   Mean   :1.199  
##  3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100   3rd Qu.:1.800  
##  Max.   :7.900   Max.   :4.400   Max.   :6.900   Max.   :2.500  
##        Species  
##  setosa    :50  
##  versicolor:50  
##  virginica :50  
##                 
##                 
## 
##     Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
## 1            5.1         3.5          1.4         0.2     setosa
## 2            4.9         3.0          1.4         0.2     setosa
## 51           7.0         3.2          4.7         1.4 versicolor
## 52           6.4         3.2          4.5         1.5 versicolor
## 5            5.0         3.6          1.4         0.2     setosa
## 101          6.3         3.3          6.0         2.5  virginica
## 102          5.8         2.7          5.1         1.9  virginica

require(sqldf)
x <- iris
names(x) <- c("slength", "swidth", "plength", "pwidth", "species")
sqldf("select * from x limit 5")
##   slength swidth plength pwidth species
## 1     5.1    3.5     1.4    0.2  setosa
## 2     4.9    3.0     1.4    0.2  setosa
## 3     4.7    3.2     1.3    0.2  setosa
## 4     4.6    3.1     1.5    0.2  setosa
## 5     5.0    3.6     1.4    0.2  setosa
sqldf("select count(*) from x")
##   count(*)
## 1      150
sqldf("select species, max(slength) from x group by species")
##      species max(slength)
## 1     setosa          5.8
## 2 versicolor          7.0
## 3  virginica          7.9