-
Notifications
You must be signed in to change notification settings - Fork 29
/
rcall_check.ado
140 lines (109 loc) · 4.61 KB
/
rcall_check.ado
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/***
_v. 1.0.0_
rcall_check
===========
examines the required version of R and R packages
Syntax
------
> __rcall_check__ [_pkgname>=version_] [[...]] [, _options_]
| _option_ | _Description_ |
|:------------------------|:-----------------------------------------------|
| **r**version(_str_) | specify the minimum required R version |
| **rcall**version(_str_) | specify the minimum required __rcall__ version |
Description
-----------
__rcall_check__ can be used to check that R is accessible via __rcall__,
check for the required R packages, and specify a minimum acceptable versions for R,
__rcall__ , and all the required R packages.
As showed in the syntax, all of the arguments are optional. If __rcall_check__
is executed without any argument or option, it simply checks whether R is
accessible via __rcall__ and returns __r(rc)__ and __r(version)__ which is the version of
the R that is used by the package. If R is not reachable, an error is returned
accordingly.
Example(s)
----------
checking that R is accessuble via rcall
. rcall_check
check that the minimum rcall version 1.3.3, ggplot2 version 2.1.0, and R version of 3.1.0 are installed
. rcall_check ggplot2>=2.1.0 , r(3.1.0) rcall(1.3.3)
Stored results
--------------
### Scalars
> __r(rc)__: indicates whether R was accessible via __rcall__ package
> __r(version)__: returns R version accessed by __rcall__
***/
*cap prog drop rcall_check
program rcall_check
syntax [anything] [, Rversion(str) RCALLversion(str)]
// Prepare the required rcall version
// -------------------------------------------------------------------------
if !missing("`rcallversion'") {
// Check rcall version from the github version
qui github version rcall
local current `r(version)'
local current : subinstr local current "." " ", all
tokenize `current'
local ver `1'
macro shift
while !missing("`1'") {
local next `next'`1'
macro shift
}
local CURRENTRCALLVERSION `ver'.`next'
// check the required rcall version
local requiredversion `rcallversion'
local requiredversion : subinstr local requiredversion "." " ", all
tokenize `requiredversion'
local version `1'
macro shift
while !missing("`1'") {
local secondary `secondary'`1'
macro shift
}
local version `version'.`secondary'
// return error if rcall is old
if `version' > `CURRENTRCALLVERSION' {
display as err "{help rcall} version `rcallversion' or newer is " ///
"required"
err 198
}
}
// Check that R is executable
// -------------------------------------------------------------------------
rcall vanilla: ///
major = R.Version()\$major; minor = R.Version()\$minor; ///
version = paste(major,minor, sep="."); ///
if ("`anything'" != "") { ///
pkglist = unlist(strsplit("`anything'", " +")); ///
for (i in 1:length(pkglist)) { ///
pkg = unlist(strsplit(pkglist[i], ">=")); ///
if (try(require(pkg[1], character.only = TRUE)) == FALSE) { ///
error = paste("R package", pkg[1], "is required"); ///
break; ///
}; ///
if (packageVersion(pkg[1]) < pkg[2]) { ///
error = paste("R package", pkg[1], pkg[2], ///
"or newer is required"); ///
break; ///
}; ///
}; ///
}; ///
suppressWarnings(rm(i, pkg, pkglist, major, minor));
// Return propper error
// -------------------------------------------------------------------------
if !missing(r(error)) {
display as err "`r(error)'"
err 198
}
else if missing(r(version)) {
di as err "{help rcall} could not access R on your system"
err 198
}
// Check R version
// -------------------------------------------------------------------------
if "`rversion'" > "`r(version)'" {
di as err "R version `rversion' or higher is required. {help rcall} " ///
"is using R `r(version)'"
err 198
}
end