Reputation: 1287
Following works with a c()
but fails with qc()
This works:
library(wrapr)
library(data.table)
dtest <- data.table(x=1:10,y=letters[1:10])
for (i in 1:nrow(dtest)){
print(paste(i,c(dtest[i,2])))
}
#> [1] "1 a"
#> [1] "2 b"
#> [1] "3 c"
#> [1] "4 d"
#> [1] "5 e"
#> [1] "6 f"
#> [1] "7 g"
#> [1] "8 h"
#> [1] "9 i"
#> [1] "10 j"
Now if you replace c
by qc
, this doesn't work.
library(wrapr)
library(data.table)
#>
#> Attaching package: 'data.table'
#> The following object is masked from 'package:wrapr':
#>
#> :=
dtest <- data.table(x=1:10,y=letters[1:10])
for (i in 1:nrow(dtest)){
print(paste(i,qc(dtest[i,2])))
}
#> Error in eval(ei): object 'dtest' not found
Upvotes: 1
Views: 57
Reputation: 118
Sorry about that, it turned out to be a name collision in the wrapr code. I have documented and fixed it in the dev version of wrapr (available here).
Thanks for reporting that and sorry about the trouble.
Also the fixed version is just going to capture the source code and not evaluate the expression. I have added some documentation to emphasize that qc() is "quoiting c()", it has different (more aggressive) quoting behavior- doesn't just convert argument values to strings (instead captures names as strings).
library(wrapr)
library(data.table)
dtest <- data.table(x=1:10,y=letters[1:10])
for (i in 1:nrow(dtest)){
print(paste(i,qc(dtest[i,2])))
}
# [1] "1 dtest[i, 2]"
# [1] "2 dtest[i, 2]"
# [1] "3 dtest[i, 2]"
# [1] "4 dtest[i, 2]"
# [1] "5 dtest[i, 2]"
# [1] "6 dtest[i, 2]"
# [1] "7 dtest[i, 2]"
# [1] "8 dtest[i, 2]"
# [1] "9 dtest[i, 2]"
# [1] "10 dtest[i, 2]"
Upvotes: 1