-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoadPackage.R
More file actions
43 lines (35 loc) · 1.85 KB
/
LoadPackage.R
File metadata and controls
43 lines (35 loc) · 1.85 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
#################################################################################################
# Name of file LoadPackage.R #
# Creation Date 05/03/2014 #
# last modification 20/03/2014 #
# Version 1.0 #
# @Description this small @method is created to Install and load package automaticlly #
# @method /*install packages : install_pkgs */ #
# @parameter /*Name of package*/ #
# @author Djedou Zakaria #
#################################################################################################
install_pkgs <- function(pkgs) {
pkgs_miss <- pkgs[which(!pkgs %in% installed.packages()[, 1])]
if (length(pkgs_miss) > 0) {
install.packages(pkgs_miss)
}
if (length(pkgs_miss) == 0) {
message("\n ...Packages were already installed!\n")
}
# install packages not already loaded:
pkgs_miss <- pkgs[which(!pkgs %in% installed.packages()[, 1])]
if (length(pkgs_miss) > 0) {
install.packages(pkgs_miss,dependencies=TRUE)
}
# load packages not already loaded:
attached <- search()
attached_pkgs <- attached[grepl("package", attached)]
need_to_attach <- pkgs[which(!pkgs %in% gsub("package:", "", attached_pkgs))]
if (length(need_to_attach) > 0) {
for (i in 1:length(need_to_attach)) require(need_to_attach[i], character.only = TRUE)
}
if (length(need_to_attach) == 0) {
message("\n ...Packages were already loaded!\n")
}
}
install_pkgs(("RODBC"))