Re: [Rd] Puzzled about a new method for "[".

2019-11-04 Thread Hadley Wickham
For what it's worth, I don't think this strategy can work in general, because a class might have attributes that depend on its data/contents (e.g. https://vctrs.r-lib.org/articles/s3-vector.html#cached-sum). I don't think these are particularly common in practice, but it's dangerous to assume that

[Rd] Questions on the R C API

2019-11-04 Thread Morgan Morgan
Hi All, I have some questions regarding the R C API. Let's assume I have a function which is defined as follows: R file: myfunc <- function(a, b, ...) .External(Cfun, a, b, ...) C file: SEXP Cfun(SEXP args) { args = CDR(args); SEXP a = CAR(args); args = CDR(args); SEXP b = CAR(args); ar

Re: [Rd] Puzzled about a new method for "[".

2019-11-04 Thread Rolf Turner
On 5/11/19 3:41 AM, Hadley Wickham wrote: For what it's worth, I don't think this strategy can work in general, because a class might have attributes that depend on its data/contents (e.g. https://vctrs.r-lib.org/articles/s3-vector.html#cached-sum). I don't think these are particularly common

Re: [Rd] Puzzled about a new method for "[".

2019-11-04 Thread Pages, Herve
Hi Rolf, On 11/4/19 12:28, Rolf Turner wrote: > > On 5/11/19 3:41 AM, Hadley Wickham wrote: > >> For what it's worth, I don't think this strategy can work in general, >> because a class might have attributes that depend on its data/contents >> (e.g. >> https://urldefense.proofpoint.com/v2/url?u

Re: [Rd] Puzzled about a new method for "[".

2019-11-04 Thread William Dunlap via R-devel
> the perils certainly are not immediately apparent to me. Here is a concrete example of a peril `[.myclass` <- function(x, i, j, drop = if (missing(i)) TRUE else length(cols) == 1) { SaveAt <- lapply(x, attributes) x <- NextMethod() lX <- lapply(names(x),function(nm, x, S

Re: [Rd] Puzzled about a new method for "[".

2019-11-04 Thread Duncan Murdoch
On 04/11/2019 4:40 p.m., Pages, Herve wrote: Hi Rolf, On 11/4/19 12:28, Rolf Turner wrote: On 5/11/19 3:41 AM, Hadley Wickham wrote: For what it's worth, I don't think this strategy can work in general, because a class might have attributes that depend on its data/contents (e.g. https://urld

Re: [Rd] Puzzled about a new method for "[".

2019-11-04 Thread Rolf Turner
On 5/11/19 10:54 AM, Duncan Murdoch wrote: On 04/11/2019 4:40 p.m., Pages, Herve wrote: Hi Rolf, On 11/4/19 12:28, Rolf Turner wrote: On 5/11/19 3:41 AM, Hadley Wickham wrote: For what it's worth, I don't think this strategy can work in general, because a class might have attributes that de

Re: [Rd] Puzzled about a new method for "[".

2019-11-04 Thread Pages, Herve
On 11/4/19 13:54, Duncan Murdoch wrote: > On 04/11/2019 4:40 p.m., Pages, Herve wrote: >> Hi Rolf, >> >> On 11/4/19 12:28, Rolf Turner wrote: >>> >>> On 5/11/19 3:41 AM, Hadley Wickham wrote: >>> For what it's worth, I don't think this strategy can work in general, because a class might

Re: [Rd] Questions on the R C API

2019-11-04 Thread Wang Jiefei
Hi Morgan, My solutions might not be the best one(I believe it's not), but it should work for your question. 1. Have you considered Rf_duplicate function? If you want to change the value of `a` and reset it later, you have to have a duplication somewhere for resetting it. Instead of changing the

Re: [Rd] Questions on the R C API

2019-11-04 Thread Morgan Morgan
Thank you for your reply Jiefei. I think in theory your solution should work. I'll have to give them a try. On Mon, 4 Nov 2019 23:41 Wang Jiefei, wrote: > Hi Morgan, > > My solutions might not be the best one(I believe it's not), but it should > work for your question. > > 1. Have you considere