Skip to content

Commit a77f31d

Browse files
Use local() for library loading
1 parent f7c99fc commit a77f31d

14 files changed

+134
-135
lines changed

PubMedTrends.R

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# http://rpsychologist.com/an-r-script-to-automatically-look-at-pubmed-citation-counts-by-year-of-publication/
22

3-
tmp_require_package_namespace <- function(...) {
4-
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
5-
for (p in packages) if (!requireNamespace(p)) install.packages(p)
6-
}
7-
tmp_require_package_namespace(
8-
RCurl, # before RCurl installation: sudo apt-get install libcurl3-dev
9-
XML,
10-
plyr, # THIS FILE MAY BE BROKEN: REMOVED PLYR BUT NOT UPDATED
11-
ggplot2,
12-
directlabels
13-
)
14-
rm(tmp_require_package_namespace)
3+
local({
4+
tmp_require_package_namespace <- function(...) {
5+
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
6+
for (p in packages) if (!requireNamespace(p)) install.packages(p)
7+
}
8+
tmp_require_package_namespace(
9+
RCurl, # before RCurl installation: sudo apt-get install libcurl3-dev
10+
XML,
11+
plyr, # THIS FILE MAY BE BROKEN: REMOVED PLYR BUT NOT UPDATED
12+
ggplot2,
13+
directlabels
14+
)
15+
})
1516

1617

1718
#==============================================================================

dbfunc.R

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/usr/bin/env Rscript
22

3-
tmp_require_package_namespace <- function(...) {
4-
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
5-
for (p in packages) if (!requireNamespace(p)) install.packages(p)
6-
}
7-
tmp_require_package_namespace(
8-
data.table,
9-
RODBC
10-
)
11-
rm(tmp_require_package_namespace)
3+
local({
4+
tmp_require_package_namespace <- function(...) {
5+
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
6+
for (p in packages) if (!requireNamespace(p)) install.packages(p)
7+
}
8+
tmp_require_package_namespace(
9+
data.table,
10+
RODBC
11+
)
12+
})
1213

1314

1415
# =============================================================================

debugfunc.R

-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
# debugfunc.R
22

3-
# tmp_require_package_namespace <- function(...) {
4-
# packages <- as.character(match.call(expand.dots = FALSE)[[2]])
5-
# for (p in packages) if (!requireNamespace(p)) install.packages(p)
6-
# }
7-
# tmp_require_package_namespace(
8-
# xtermStyle
9-
# )
10-
# rm(tmp_require_package_namespace)
11-
12-
133
# =============================================================================
144
# Namespace-like method: http://stackoverflow.com/questions/1266279/#1319786
155
# =============================================================================

dirichlet.R

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
dirichlet <- new.env()
88

9+
910
#==============================================================================
1011
# Stephan et al. (2009) Neuroimage: Dirichlet parameter estimation
1112
#==============================================================================

infotheoryfunc.R

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ infotheoryfunc$f_nij <- function(v1, v2, l1, l2) # contingency table n(i,j)=t(i
2121
m
2222
}
2323

24-
2524
infotheoryfunc$f_emi <- function(s1, s2, l1, l2, n) # expected mutual information
2625
{
2726
s_emi <- 0
@@ -55,7 +54,7 @@ infotheoryfunc$f_nmi_ami <- function(v1, v2)
5554
l1 <- length(s1)
5655
l2 <- length(s2)
5756
N <- length(v1)
58-
tij <- infotheoryfunc$f_nij(v1, v2, l1, l2) # contingency table n(i,j)=t(i,j). this would be equivalent with table(v1,v2)
57+
# tij <- infotheoryfunc$f_nij(v1, v2, l1, l2) # contingency table n(i,j)=t(i,j). this would be equivalent with table(v1,v2)
5958
mi <- infotheo::mutinformation(v1, v2) # function for Mutual Information from package infotheo
6059
h1 <- -sum(s1 * log(s1/N)) / N
6160
h2 <- -sum(s2 * log(s2/N)) / N

mapfunc.R

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
# mapfunc.R
22

3-
# Packages:
4-
tmp_require_package_namespace <- function(...) {
5-
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
6-
for (p in packages) if (!requireNamespace(p)) install.packages(p)
7-
}
8-
tmp_require_package_namespace(
9-
data.table,
10-
broom,
11-
ggplot2,
12-
maptools,
13-
raster, # Linux: use "sudo apt install libgeos-dev" first
14-
rgdal, # Linux: use "sudo apt install libgdal-dev libproj-dev" first
15-
rgeos,
16-
sp
17-
)
18-
rm(tmp_require_package_namespace)
3+
local({
4+
# Packages:
5+
tmp_require_package_namespace <- function(...) {
6+
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
7+
for (p in packages) if (!requireNamespace(p)) install.packages(p)
8+
}
9+
tmp_require_package_namespace(
10+
data.table,
11+
broom,
12+
ggplot2,
13+
maptools,
14+
raster, # Linux: use "sudo apt install libgeos-dev" first
15+
rgdal, # Linux: use "sudo apt install libgdal-dev libproj-dev" first
16+
rgeos,
17+
sp
18+
)
19+
})
1920

2021
# Try this, for our local ones:
2122
# requireNamespace("miscfile") # nope, fails

miscfile.R

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# miscfile.R
22

3-
tmp_require_package_namespace <- function(...) {
4-
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
5-
for (p in packages) if (!requireNamespace(p)) install.packages(p)
6-
}
7-
tmp_require_package_namespace(
8-
data.table,
9-
openxlsx
10-
)
11-
rm(tmp_require_package_namespace)
3+
local({
4+
tmp_require_package_namespace <- function(...) {
5+
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
6+
for (p in packages) if (!requireNamespace(p)) install.packages(p)
7+
}
8+
tmp_require_package_namespace(
9+
data.table,
10+
openxlsx
11+
)
12+
})
1213

1314

1415
# =============================================================================

misclang.R

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
misclang <- new.env()
88

9+
910
#==============================================================================
1011
# Libraries
1112
#==============================================================================

miscplot.R

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
# miscplot.R
22

3-
tmp_require_package_namespace <- function(...) {
4-
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
5-
for (p in packages) if (!requireNamespace(p)) install.packages(p)
6-
}
7-
tmp_require_package_namespace(
8-
grid, # for gpar, etc.
9-
ggplot2,
10-
gridExtra,
11-
# extrafont, # install with sudo. Then (with sudo R) run font_import() then loadfonts(). Then view with fonts() or fonttable(). See https://github.com/wch/extrafont
12-
Cairo,
13-
ggplot2
14-
)
15-
rm(tmp_require_package_namespace)
3+
local({
4+
tmp_require_package_namespace <- function(...) {
5+
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
6+
for (p in packages) if (!requireNamespace(p)) install.packages(p)
7+
}
8+
tmp_require_package_namespace(
9+
grid, # for gpar, etc.
10+
ggplot2,
11+
gridExtra,
12+
# extrafont, # install with sudo. Then (with sudo R) run font_import() then loadfonts(). Then view with fonts() or fonttable(). See https://github.com/wch/extrafont
13+
Cairo,
14+
ggplot2
15+
)
16+
})
1617

1718

1819
#==============================================================================

miscresults.R

+14-14
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@
3939
# - code: `x`
4040
# - underline: [x]{.underline}
4141

42-
43-
tmp_require_package_namespace <- function(...) {
44-
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
45-
for (p in packages) if (!requireNamespace(p)) install.packages(p)
46-
}
47-
tmp_require_package_namespace(
48-
car, # for car::Anova
49-
flextable,
50-
ftExtra, # for markup within flextable tables
51-
rcompanion, # for wilcoxonZ
52-
rlang, # for dots_n
53-
tidyverse
54-
)
55-
rm(tmp_require_package_namespace)
42+
local({
43+
tmp_require_package_namespace <- function(...) {
44+
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
45+
for (p in packages) if (!requireNamespace(p)) install.packages(p)
46+
}
47+
tmp_require_package_namespace(
48+
car, # for car::Anova
49+
flextable,
50+
ftExtra, # for markup within flextable tables
51+
rcompanion, # for wilcoxonZ
52+
rlang, # for dots_n
53+
tidyverse
54+
)
55+
})
5656

5757

5858
# =============================================================================

miscstat.R

+16-15
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
# miscstat.R
22

3-
tmp_require_package_namespace <- function(...) {
4-
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
5-
for (p in packages) if (!requireNamespace(p)) install.packages(p)
6-
}
7-
tmp_require_package_namespace(
8-
data.table,
9-
ggplot2,
10-
lmerTest,
11-
emmeans,
12-
MASS,
13-
moments,
14-
multcomp,
15-
plyr
16-
)
17-
rm(tmp_require_package_namespace)
3+
local({
4+
tmp_require_package_namespace <- function(...) {
5+
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
6+
for (p in packages) if (!requireNamespace(p)) install.packages(p)
7+
}
8+
tmp_require_package_namespace(
9+
data.table,
10+
ggplot2,
11+
lmerTest,
12+
emmeans,
13+
MASS,
14+
moments,
15+
multcomp,
16+
plyr
17+
)
18+
})
1819

1920

2021
# =============================================================================

miscvisualize.R

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# miscvisualize.R
22

3-
tmp_require_package_namespace <- function(...) {
4-
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
5-
for (p in packages) if (!requireNamespace(p)) install.packages(p)
6-
}
7-
tmp_require_package_namespace(
8-
arm,
9-
ggplot2
10-
)
11-
rm(tmp_require_package_namespace)
3+
local({
4+
tmp_require_package_namespace <- function(...) {
5+
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
6+
for (p in packages) if (!requireNamespace(p)) install.packages(p)
7+
}
8+
tmp_require_package_namespace(
9+
arm,
10+
ggplot2
11+
)
12+
})
1213

1314

1415
#==============================================================================

stanfunc.R

+18-18
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
# https://stackoverflow.com/questions/32988099/data-table-objects-not-printed-after-returned-from-function
66
# https://github.com/Rdatatable/data.table/blob/master/NEWS.md#bug-fixes-5
77

8-
9-
tmp_require_package_namespace <- function(...) {
10-
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
11-
for (p in packages) if (!requireNamespace(p)) install.packages(p)
12-
}
13-
tmp_require_package_namespace(
14-
bridgesampling,
15-
coda,
16-
data.table,
17-
ggplot2,
18-
HDInterval,
19-
matrixStats,
20-
parallel,
21-
reshape,
22-
rstan,
23-
stringr
24-
)
25-
rm(tmp_require_package_namespace)
8+
local({
9+
tmp_require_package_namespace <- function(...) {
10+
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
11+
for (p in packages) if (!requireNamespace(p)) install.packages(p)
12+
}
13+
tmp_require_package_namespace(
14+
bridgesampling,
15+
coda,
16+
data.table,
17+
ggplot2,
18+
HDInterval,
19+
matrixStats,
20+
parallel,
21+
reshape,
22+
rstan,
23+
stringr
24+
)
25+
})
2626

2727

2828
#==============================================================================

stringfunc.R

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/env Rscript
22

3-
tmp_require_package_namespace <- function(...) {
4-
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
5-
for (p in packages) if (!requireNamespace(p)) install.packages(p)
6-
}
7-
tmp_require_package_namespace(
8-
gsubfn
9-
)
10-
rm(tmp_require_package_namespace)
3+
local({
4+
tmp_require_package_namespace <- function(...) {
5+
packages <- as.character(match.call(expand.dots = FALSE)[[2]])
6+
for (p in packages) if (!requireNamespace(p)) install.packages(p)
7+
}
8+
tmp_require_package_namespace(
9+
gsubfn
10+
)
11+
})
1112

1213

1314
# =============================================================================

0 commit comments

Comments
 (0)