[Rd] Issue when calling deparse(substitute(x)) from C with "anonymous" R vectors ?
lgautier at gmail.com
Thu Nov 19 08:40:12 CET 2009
When calling R from C, what appears like a spurious error can be
triggered during the execution of chisq.test(x, y).
This is happening when the following conditions are met:
- x and y are "anonymous" C-level R vectors (they do not have a symbol),
but they are protected from garbage collection
- x and y are "not too small" (it was experienced as soon as they are
longer than 17 elements).
The error is
Error in names(dimnames(x)) <- DNAME :
'names' attribute  must be the same length as the vector 
and can be traced to the use of deparse(substitute(x)) and
deparse(substitute(y)) in the R code.
What seems to be happening is that the deparse(substitute(x)) call
gives a character vector of length > 1 as soon as x is "not so small".
To demonstrate this, I am using rpy2 (as the problem was found when using it
), but it will likely be present in other bridges to R as well.
#using R-2.10 and rpy2-2.1.dev
>>> import rpy2.robjects as robjects
>>> f = robjects.r('''function(x) return(deparse(substitute(x)))''')
('c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)',)
# length 1
('c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17', ')')
# length 2 !!
Does it seem to others like an issue present in other bridges as well ?
More information about the R-devel