# Lab Management Log
### Nov 18 2019
## R request from Professor Andre Bonfrer
### Install R Package into Users Folder
1. Check the lib Paths:
> \> .libPaths()
2. Set the user folder as package installation path:
> \> .libPaths("H:/R")
_before setting, please make sure the folder **exists** and located in a path with **permission**_
3. install packages:
> \> install.packages("xxx")
### High-Performance and Parallel Computing with R
#### parallel Package:
[Parallel Processing in R](http://dept.stat.lsa.umich.edu/~jerrick/courses/stat701/notes/parallel.html)
Code Example:
**Only sockets with parLapply appoarch works on windows**
> \> .libPaths("H:/R")
> \> library(parallel)
> \> numCores <- detectCores()
> \> numCores ## Show the number of cores
> \> f <- function(x){} ## Pre-define your function
> \> cl <- makeCluster(numCores) ## Create a cluster
> \> clusterEvalQ(cl, .libPaths("H:/R")) ## for each cluster, relocate the lib path to your path
> \> install.packages("lme4") ## install packages you would like to include
> \> clusterEvalQ(cl, library(lme4)) ## load packages for clusters before you use them
> \> save <- parLapply(cl, data, f) ## run your function with parLapply
> \> stopCluster(cl) ## stop cluster
**Each Cluster is created from nothing, so even though you already loaded packages in your current R session, you still need to load them in cluster setting**