[R-SIG-Finance] R class accessor problem in 2.6
Joseph Wang
joe at gnacademy.org
Sun Feb 3 23:42:10 CET 2008
I was able to track down the problem that causes R-Swig to fail in 2.6.
In 2.5, I am able to use the set method against '$' and '$<-' to cause
expressions like r$d to get dispatched to get and set functions. This no
longer seems to work in 2.6, and I was wondering if anyone can give
information as why.
The function that are failing are at the end of this e-mail. In 2.5 a
function like r$d would get dispatched to A_d_get(r). but in 2.6 it returns a
NULL.
# Start of accessor method for A
setMethod('$', '_p_A', function(x, name)
{
print('foo')
accessorFuns = list('i' = A_i_get, 'ui' = A_ui_get, 'd' = A_d_get, 'str' =
A_str_get, 'tmp' = A_tmp_get)
vaccessors = c('i', 'ui', 'd', 'str', 'tmp')
idx = pmatch(name, names(accessorFuns))
if(is.na(idx))
return(callNextMethod(x, name))
f = accessorFuns[[idx]]
formals(f)[[1]] = x
if (is.na(match(name, vaccessors))) f else f(x)
}
)
# end of accessor method for A
# Start of accessor method for A
setMethod('$<-', '_p_A', function(x, name, value)
{
accessorFuns = list('i' = A_i_set, 'ui' = A_ui_set, 'd' = A_d_set, 'str' =
A_str_set, 'tmp' = A_tmp_set)
idx = pmatch(name, names(accessorFuns))
if(is.na(idx))
return(callNextMethod(x, name, value))
f = accessorFuns[[idx]]
f(x, value)
x
}
More information about the R-SIG-Finance
mailing list