Re: [Rd] Need help on calling Head from C

2014-06-27 Thread Radford Neal
> >> SEXP mkans(double x) > >> { > >> SEXP ans; > >> ans = PROTECT(allocVector(REALSXP, 1)); > >> REAL(ans)[0] = x; > >> UNPROTECT(1); > >> return ans; > >> } > >One should also note that the PROTECT within mkans is unnecessary, > >and must surely be confusing to anyone w

Re: [Rd] Need help on calling Head from C

2014-06-27 Thread Hervé Pagès
On 06/27/2014 02:23 AM, Radford Neal wrote: The code is actually not safe. Both "install" and "SalarLogical/Integer" potentially allocate memory, so at least one needs to be protected before callling lang3. (Passing one such argument would be OK, since lang3 protects its arguments, but it doesn

Re: [Rd] Need help on calling Head from C

2014-06-27 Thread Radford Neal
> >The code is actually not safe. Both "install" and "SalarLogical/Integer" > >potentially allocate memory, so at least one needs to be protected before > >callling lang3. (Passing one such argument would be OK, since lang3 > >protects its arguments, but it doesn't get a chance to do that while t

Re: [Rd] Need help on calling Head from C

2014-06-26 Thread Hervé Pagès
Hi, On 06/26/2014 01:36 PM, Radford Neal wrote: PROTECT(dfm=lang3(install("data.frame"),df,ScalarLogical(FALSE))); SET_TAG(CDDR(dfm), install("stringsAsFactors")) ; SEXP res = PROTECT(eval(dfm,R_GlobalEnv)); PROTECT(head=lang3(install("head"),res,ScalarInteger(1))); head = PROTECT(eval(head,R_G

Re: [Rd] Need help on calling Head from C

2014-06-26 Thread Sandip Nandi
Thank you very much . I forgot one thing in my code SET_TAG(CDDR(head), install("n")) ; after that it works Thanks again, Sandip On Thu, Jun 26, 2014 at 2:25 PM, Radford Neal wrote: > > Thank you for the wonderful suggestion . do you suggest to protect > > ScalarInteger(1) > > before calling

Re: [Rd] Need help on calling Head from C

2014-06-26 Thread Radford Neal
> Thank you for the wonderful suggestion . do you suggest to protect > ScalarInteger(1) > before calling lang3 ? Yes, either the result of Scalar Integer(1) or the result of install should be protected (before calling lang3 - don't try to do it inside the argument list of lang3). ___

Re: [Rd] Need help on calling Head from C

2014-06-26 Thread Sandip Nandi
Thank you for the wonderful suggestion . do you suggest to protect ScalarInteger(1) before calling lang3 ? Thanks On Thu, Jun 26, 2014 at 1:36 PM, Radford Neal wrote: > >> PROTECT(dfm=lang3(install("data.frame"),df,ScalarLogical(FALSE))); > >> SET_TAG(CDDR(dfm), install("stringsAsFactors")) ;

[Rd] Need help on calling Head from C

2014-06-26 Thread Radford Neal
>> PROTECT(dfm=lang3(install("data.frame"),df,ScalarLogical(FALSE))); >> SET_TAG(CDDR(dfm), install("stringsAsFactors")) ; >> SEXP res = PROTECT(eval(dfm,R_GlobalEnv)); >> PROTECT(head=lang3(install("head"),res,ScalarInteger(1))); >> head = PROTECT(eval(head,R_GlobalEnv)); >> >> >> I tried the a

Re: [Rd] Need help on calling Head from C

2014-06-26 Thread Sandip Nandi
Hi , Sorry . I am very sorry . Such a mistake . Sorry for the email . Thanks, Sandip On Thu, Jun 26, 2014 at 9:10 AM, Sandip Nandi wrote: > Hi , > > I am trying to implement the following from C > > > x > a b > 1 1 2 > 2 3 4 > > r<- head(x,n=1) > > r > a b > 1 1 2 > > I tried my code ,

Re: [Rd] Need help on calling Head from C

2014-06-26 Thread Sandip Nandi
Hi , I am trying to implement the following from C > x a b 1 1 2 2 3 4 r<- head(x,n=1) > r a b 1 1 2 I tried my code , its not working , its not working for the value of the parameter n Thanks, Sandip On Thu, Jun 26, 2014 at 12:50 AM, Simon Urbanek wrote: > On Jun 25, 2014, at 11:31

Re: [Rd] Need help on calling Head from C

2014-06-26 Thread Simon Urbanek
On Jun 25, 2014, at 11:31 PM, Sandip Nandi wrote: > Hi , > > I am trying to call head function from C . My doubt is with the parameter > n,how to pass it . > > PROTECT(dfm=lang3(install("data.frame"),df,ScalarLogical(FALSE))); > SET_TAG(CDDR(dfm), install("stringsAsFactors")) ; > SEXP res = PRO

[Rd] Need help on calling Head from C

2014-06-25 Thread Sandip Nandi
Hi , I am trying to call head function from C . My doubt is with the parameter n,how to pass it . PROTECT(dfm=lang3(install("data.frame"),df,ScalarLogical(FALSE))); SET_TAG(CDDR(dfm), install("stringsAsFactors")) ; SEXP res = PROTECT(eval(dfm,R_GlobalEnv)); PROTECT(head=lang3(install("head"),res,