-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackageLoaderAndBibliographyTest.Rmd
More file actions
53 lines (44 loc) · 1.39 KB
/
packageLoaderAndBibliographyTest.Rmd
File metadata and controls
53 lines (44 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
---
title: "R Notebook"
output:
html_document: default
html_notebook: default
bibliography: ~/bibliography.bib
---
# Create function to install packages
This is Luke Blunden's really nice function for installing packages that can't be loaded. Use with caution in a script which may not have internet access...
```{r, cache=TRUE}
# This is a function to install any packages that cannot be loaded
myRequiredPackages <- function(x,y){
for( i in x ){
# require returns TRUE if it was able to load package
if( ! require( i , character.only = TRUE ) ){
# If package was not able to be loaded then re-install
install.packages( i , repos=y ,
#type="win.binary" , comment out so runs on OS X etc
quiet=TRUE , dependencies = TRUE , verbose = FALSE )
# Load package after installing
require( i , character.only = TRUE, quietly = TRUE )
}
}
}
```
#Load required libraries
```{r echo=TRUE}
# warning=FALSE, message=FALSE
# the options above suppress/show any warnings & messages
# call the function my_required_packages
myRequiredPackages(c("car",
"data.table", # fast data munching
"knitr"
),"http://cran.rstudio.com/")
```
Packages used:
* car - [@car]
* data.table - [@data.table]
* knitr = [@knitr]
Check they were loaded:
```{r }
print(search())
```
# References