Skip to content

Commit 9d20600

Browse files
committed
v0.2.18 MTN R-devel API restrictions
2 parents 6ffdfc9 + 549880a commit 9d20600

File tree

9 files changed

+51
-23
lines changed

9 files changed

+51
-23
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Title: Trust, but Verify
33
Description: Declarative template-based framework for verifying that objects
44
meet structural requirements, and auto-composing error messages when they do
55
not.
6-
Version: 0.2.16
6+
Version: 0.2.18
77
Authors@R: c(
88
person("Brodie", "Gaslam", email="[email protected]",
99
role=c("aut", "cre")),

NEWS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 0.2.17-18
2+
3+
* Fix bad C API accesses uncovered by new R-devel checks.
4+
5+
## 0.2.16
6+
7+
* Fix -Wformat warnings.
8+
19
## 0.2.15
210

311
* [#109](https://github.com/brodieG/vetr/issues/109) allow for substituted

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ care of the rest:
4747
tpl <- numeric(1L)
4848
vet(tpl, 1:3)
4949
## [1] "`length(1:3)` should be 1 (is 3)"
50+
5051
vet(tpl, "hello")
5152
## [1] "`\"hello\"` should be type \"numeric\" (is \"character\")"
53+
5254
vet(tpl, 42)
5355
## [1] TRUE
5456

@@ -59,6 +61,7 @@ example, zero length templates match any length:
5961
tpl <- integer()
6062
vet(tpl, 1L:3L)
6163
## [1] TRUE
64+
6265
vet(tpl, 1L)
6366
## [1] TRUE
6467

@@ -68,6 +71,7 @@ considered integer:
6871
tpl <- integer(1L)
6972
vet(tpl, 1) # this is a numeric, not an integer
7073
## [1] TRUE
74+
7175
vet(tpl, 1.0001)
7276
## [1] "`1.0001` should be type \"integer-like\" (is \"double\")"
7377

@@ -79,6 +83,7 @@ considered integer:
7983

8084
vet(tpl.iris, iris)
8185
## [1] TRUE
86+
8287
vet(tpl.iris, iris.fake)
8388
## [1] "`levels(iris.fake$Species)[3]` should be \"virginica\" (is \"sibirica\")"
8489

@@ -134,8 +139,10 @@ You can combine templates with `&&` / `||`:
134139

135140
vet(numeric(1L) || NULL, NULL)
136141
## [1] TRUE
142+
137143
vet(numeric(1L) || NULL, 42)
138144
## [1] TRUE
145+
139146
vet(numeric(1L) || NULL, "foo")
140147
## [1] "`\"foo\"` should be `NULL`, or type \"numeric\" (is \"character\")"
141148

@@ -144,6 +151,7 @@ refer to the object:
144151

145152
vet(numeric(1L) && . > 0, -42) # strictly positive scalar numeric
146153
## [1] "`-42 > 0` is not TRUE (FALSE)"
154+
147155
vet(numeric(1L) && . > 0, 42)
148156
## [1] TRUE
149157

@@ -161,8 +169,10 @@ them:
161169

162170
vet(vet.exp, 42)
163171
## [1] TRUE
172+
164173
vet(vet.exp, "foo")
165174
## [1] TRUE
175+
166176
vet(vet.exp, "baz")
167177
## [1] "At least one of these should pass:"
168178
## [2] " - `\"baz\" %in% c(\"foo\", \"bar\")` is not TRUE (FALSE)"
@@ -172,7 +182,7 @@ them:
172182
`isTRUE(all(. >= x & . <= y))` for large vectors):
173183

174184
vet(all_bw(., 0, 1), runif(5) + 1)
175-
## [1] "`all_bw(runif(5) + 1, 0, 1)` is not TRUE (is chr: \"`1.234342` at index 1 not in `[0,1]`\")"
185+
## [1] "`all_bw(runif(5) + 1, 0, 1)` is not TRUE (is chr: \"`1.614709` at index 1 not in `[0,1]`\")"
176186

177187
There are a number of predefined vetting tokens you can use in your
178188
vetting expressions such as:
@@ -198,6 +208,7 @@ functions:
198208
}
199209
fun(1:2, "foo")
200210
## Error in fun(x = 1:2, y = "foo"): For argument `x`, `length(1:2)` should be 1 (is 2)
211+
201212
fun(1, "foo")
202213
## Error in fun(x = 1, y = "foo"): For argument `y`, `"foo"` should be type "logical" (is "character")
203214

@@ -280,9 +291,9 @@ review them:
280291
- [`validate`](https://github.com/data-cleaning/validate) by Mark van
281292
der Loo and Edwin de Jonge, with a primary focus on validating data
282293
in data frames and similar data structures.
283-
- [`assertr`](https://github.com/ropensci/assertr) by Tony Fischetti,
284-
also focused on data validation in data frames and similar
285-
structures.
294+
- [`assertr`](https://github.com/tonyfischetti/assertr) by Tony
295+
Fischetti, also focused on data validation in data frames and
296+
similar structures.
286297
- [`types`](https://github.com/jimhester/types) by Jim Hester, which
287298
implements but does not enforce type hinting.
288299
- [`argufy`](https://github.com/gaborcsardi/argufy) by Gábor Csárdi,

src/alike.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ Go to <https://www.r-project.org/Licenses/GPL-2> for a copy of the license.
263263
extern SEXP ALIKEC_SYM_tilde;
264264
extern SEXP ALIKEC_SYM_paren_open;
265265
extern SEXP ALIKEC_SYM_args;
266+
extern SEXP ALIKEC_SYM_function;
266267
extern SEXP ALIKEC_SYM_deparse;
267268
extern SEXP ALIKEC_SYM_nlines;
268269
extern SEXP ALIKEC_SYM_getOption;

src/fun.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,17 @@ struct ALIKEC_res ALIKEC_fun_alike_internal(
4646
if(!isFunction(target) || !isFunction(current))
4747
error("Arguments must be functions.");
4848

49-
SEXP tar_form, cur_form, args;
49+
SEXP tar_form, cur_form, args, func;
5050
SEXPTYPE tar_type = TYPEOF(target), cur_type = TYPEOF(current);
5151
struct ALIKEC_res res = ALIKEC_res_init();
5252

5353
// Translate specials and builtins to formals, if possible
5454

5555
args = PROTECT(list2(ALIKEC_SYM_args, R_NilValue));
56-
if(
57-
tar_type == SPECIALSXP || tar_type == BUILTINSXP ||
58-
cur_type == SPECIALSXP || cur_type == BUILTINSXP
59-
) {
60-
SET_TYPEOF(args, LANGSXP);
61-
}
56+
SET_TYPEOF(args, LANGSXP);
57+
func = PROTECT(list3(ALIKEC_SYM_function, R_NilValue, R_NilValue));
58+
SET_TYPEOF(func, LANGSXP);
59+
6260
if(tar_type == SPECIALSXP || tar_type == BUILTINSXP) {
6361
SETCADR(args, target);
6462
target = PROTECT(eval(args, R_BaseEnv));
@@ -69,6 +67,16 @@ struct ALIKEC_res ALIKEC_fun_alike_internal(
6967
current = PROTECT(eval(args, R_BaseEnv));
7068
} else PROTECT(R_NilValue);
7169

70+
// As of ~r86700 R became stricter about what we could call FORMALS on, so we
71+
// need to make sure that we do get actual formals and not NULL.
72+
73+
if(TYPEOF(target) != CLOSXP) {
74+
target = PROTECT(eval(func, R_BaseEnv));
75+
} else PROTECT(R_NilValue);
76+
if(TYPEOF(current) != CLOSXP) {
77+
current = PROTECT(eval(func, R_BaseEnv));
78+
} else PROTECT(R_NilValue);
79+
7280
// Cycle through all formals
7381

7482
int dots = 0, dots_last = 0, dots_reset = 0, tag_match = 1, dots_cur = 0;
@@ -156,7 +164,7 @@ struct ALIKEC_res ALIKEC_fun_alike_internal(
156164
res.dat.strings.target[2] = arg_type;
157165
}
158166
}
159-
UNPROTECT(3);
167+
UNPROTECT(6);
160168
if(!res.success) res.wrap = allocVector(VECSXP, 2);
161169
return res;
162170
}

src/init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ SEXP ALIKEC_SYM_inherits;
107107
SEXP ALIKEC_SYM_paren_open;
108108
SEXP ALIKEC_SYM_tilde;
109109
SEXP ALIKEC_SYM_args;
110+
SEXP ALIKEC_SYM_function;
110111
SEXP ALIKEC_SYM_deparse;
111112
SEXP ALIKEC_SYM_nlines;
112113
SEXP ALIKEC_SYM_widthcutoff;
@@ -143,6 +144,7 @@ void R_init_vetr(DllInfo *info)
143144
ALIKEC_SYM_paren_open = install("(");
144145
ALIKEC_SYM_tilde = install("~");
145146
ALIKEC_SYM_args = install("args");
147+
ALIKEC_SYM_function = install("function");
146148
ALIKEC_SYM_deparse = install("deparse");
147149
ALIKEC_SYM_nlines = install("nlines");
148150
ALIKEC_SYM_widthcutoff = install("width.cutoff");

src/merge.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,17 @@ static SEXP ALIKEC_unique_msg(SEXP msgs) {
117117
R_xlen_t len = xlength(msgs);
118118
if(len < 2) return(msgs);
119119

120-
// Loop once to check for dupes
120+
// Loop once to count how many distinct values
121121

122-
int some_dup = 0;
122+
int distinct_vals = 1;
123123
for(R_xlen_t i = 1; i < len; ++i) {
124-
if(R_compute_identical(VECTOR_ELT(msgs, i - 1), VECTOR_ELT(msgs, i), 16)) {
125-
some_dup = 1;
126-
break;
124+
if(!R_compute_identical(VECTOR_ELT(msgs, i - 1), VECTOR_ELT(msgs, i), 16)) {
125+
++distinct_vals;
127126
}
128127
}
129128
SEXP res;
130-
if(some_dup) {
131-
res = PROTECT(allocVector(VECSXP, len));
129+
if(distinct_vals != len) {
130+
res = PROTECT(allocVector(VECSXP, distinct_vals));
132131
SET_VECTOR_ELT(res, 0, VECTOR_ELT(msgs, 0));
133132
R_xlen_t j = 1;
134133
for(R_xlen_t i = 1; i < len; ++i) {
@@ -138,7 +137,6 @@ static SEXP ALIKEC_unique_msg(SEXP msgs) {
138137
SET_VECTOR_ELT(res, j++, VECTOR_ELT(msgs, i));
139138
}
140139
}
141-
SETLENGTH(res, j);
142140
UNPROTECT(1);
143141
} else res = msgs;
144142
return res;

src/r-copied.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ SEXP ALIKEC_findFun(SEXP symbol, SEXP rho) {
6363
error("Internal Error: `rho` must be environment");// nocov
6464
SEXP vl;
6565
while (rho != R_EmptyEnv) {
66-
vl = findVarInFrame3(rho, symbol, TRUE);
66+
vl = findVarInFrame(rho, symbol);
6767
if (vl != R_UnboundValue) {
6868
if (TYPEOF(vl) == PROMSXP) {
6969
PROTECT(vl);

vignettes/rmdhunks/related-packages.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ them:
1919
* [`validate`](https://github.com/data-cleaning/validate) by Mark van
2020
der Loo and Edwin de Jonge, with a primary focus on validating data in data
2121
frames and similar data structures.
22-
* [`assertr`](https://github.com/ropensci/assertr) by Tony Fischetti, also
22+
* [`assertr`](https://github.com/tonyfischetti/assertr) by Tony Fischetti, also
2323
focused on data validation in data frames and similar structures.
2424
* [`types`](https://github.com/jimhester/types) by Jim Hester, which implements
2525
but does not enforce type hinting.

0 commit comments

Comments
 (0)