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 = PROTECT(eval(dfm,R_GlobalEnv));
> PROTECT(head=lang3(install("head"),res,ScalarInteger(1)));
> head  = PROTECT(eval(head,R_GlobalEnv));
> 
> 
> I tried the above following , it seemed to be not working . Can you please
> help.
> 

Can you elaborate? The above code works AFAICT ...

Cheers,
S



> Thanks
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Compiling R-3.1.0 on debian with libpng/libjpeg

2014-06-26 Thread Preussner, Jens
Dear r-developers,

I currently face an issue while compiling R from source on a debian wheezy. 
When running the configure script (particularly with --enable-R-shlib 
--prefix=/packages/R/3.1.0/) I get a Makefile and the output
...
  Interfaces supported:  X11
  External libraries:readline
  Additional capabilities:   PNG, JPEG, NLS
  Options enabled:   shared R library, shared BLAS, R profiling
...

After compiling and checking the capabilities, R tells me the following:
> capabilities()
jpeg  png tifftcltk  X11 aqua http/ftp  sockets
   FALSEFALSEFALSEFALSEFALSEFALSE TRUE TRUE
  libxml fifo   clediticonv  NLS  profmemcairo
TRUE TRUE TRUE TRUE TRUEFALSEFALSE

I already have R on another machine with jpeg/png capabilities, also compiled 
on my own. I crosschecked the versions of the libpng-* and libjpeg-* packages 
installed there and could not find any difference. Also returning to R-3.0.2 
doesn't work.
A last thing: The same question came up back in 2009, but there was no answer 
on the list.. https://stat.ethz.ch/pipermail/r-help/2009-December/222967.html

Any suggestions how to get more information on what is going on here?
Many thanks and best regards,

Jens


[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Compiling R-3.1.0 on debian with libpng/libjpeg

2014-06-26 Thread Prof Brian Ripley

On 26/06/2014 07:46, Preussner, Jens wrote:

Dear r-developers,

I currently face an issue while compiling R from source on a debian wheezy. 
When running the configure script (particularly with --enable-R-shlib 
--prefix=/packages/R/3.1.0/) I get a Makefile and the output
...
   Interfaces supported:  X11
   External libraries:readline
   Additional capabilities:   PNG, JPEG, NLS
   Options enabled:   shared R library, shared BLAS, R profiling
...

After compiling and checking the capabilities, R tells me the following:

capabilities()

 jpeg  png tifftcltk  X11 aqua http/ftp  sockets
FALSEFALSEFALSEFALSEFALSEFALSE TRUE TRUE
   libxml fifo   clediticonv  NLS  profmemcairo
 TRUE TRUE TRUE TRUE TRUEFALSEFALSE

I already have R on another machine with jpeg/png capabilities, also compiled 
on my own. I crosschecked the versions of the libpng-* and libjpeg-* packages 
installed there and could not find any difference. Also returning to R-3.0.2 
doesn't work.
A last thing: The same question came up back in 2009, but there was no answer 
on the list.. https://stat.ethz.ch/pipermail/r-help/2009-December/222967.html

Any suggestions how to get more information on what is going on here?


As you do not have capabilities for cairo nor X11, read ?png, e.g.

type: character string, one of ‘"Xlib"’ or ‘"quartz"’ (some OS X
  builds) or ‘"cairo"’.  The latter will only be available if
  the system was compiled with support for cairo - otherwise
  ‘"Xlib"’ will be used.  The default is set by
  ‘getOption("bitmapType")’ - the ‘out of the box’ default is
  ‘"quartz"’ or ‘"cairo"’ where available, otherwise ‘"Xlib"’.

 R can be compiled without support for some or all of the types for
 each of these devices: this will be reported if you attempt to use
 them on a system where they are not supported.  For ‘type =
 "Xlib"’ they may not be usable unless the X11 display is available
 to the owner of the R process.

So, the only type available to you appears to be "Xlib", and that 
process does not have access to an X server.


The strongly recommended solution is to get cairographics working: see
http://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Useful-libraries-and-programs


Many thanks and best regards,

Jens


[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel




--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


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 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 = PROTECT(eval(dfm,R_GlobalEnv));
> > PROTECT(head=lang3(install("head"),res,ScalarInteger(1)));
> > head  = PROTECT(eval(head,R_GlobalEnv));
> >
> >
> > I tried the above following , it seemed to be not working . Can you
> please
> > help.
> >
>
> Can you elaborate? The above code works AFAICT ...
>
> Cheers,
> S
>
>
>
> > Thanks
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-devel@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


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 , 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 <
> simon.urba...@r-project.org> wrote:
>
>> 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 = PROTECT(eval(dfm,R_GlobalEnv));
>> > PROTECT(head=lang3(install("head"),res,ScalarInteger(1)));
>> > head  = PROTECT(eval(head,R_GlobalEnv));
>> >
>> >
>> > I tried the above following , it seemed to be not working . Can you
>> please
>> > help.
>> >
>>
>> Can you elaborate? The above code works AFAICT ...
>>
>> Cheers,
>> S
>>
>>
>>
>> > Thanks
>> >
>> >   [[alternative HTML version deleted]]
>> >
>> > __
>> > R-devel@r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-devel
>> >
>>
>>
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[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 above following , it seemed to be not working . Can you please
>> help.
>> 
>
>Can you elaborate? The above code works AFAICT ...

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 they
are still being evaluated.)

Now, I'm not sure this is the source of the actual problem, since both
"data.frame" and "head" presumably already exist, so the install won't
actually allocate memory.  But this is not a safe coding method in 
general.

   Radford Neal

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


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")) ;
> >> SEXP res = PROTECT(eval(dfm,R_GlobalEnv));
> >> PROTECT(head=lang3(install("head"),res,ScalarInteger(1)));
> >> head  = PROTECT(eval(head,R_GlobalEnv));
> >>
> >>
> >> I tried the above following , it seemed to be not working . Can you
> please
> >> help.
> >>
> >
> >Can you elaborate? The above code works AFAICT ...
>
> 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 they
> are still being evaluated.)
>
> Now, I'm not sure this is the source of the actual problem, since both
> "data.frame" and "head" presumably already exist, so the install won't
> actually allocate memory.  But this is not a safe coding method in
> general.
>
>Radford Neal
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


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).

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


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 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).
>
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] using 2D array of SEXP for creating dataframe

2014-06-26 Thread Sandip Nandi
Hi ,

For our production package i need to create a dataframein C . So I wrote
the following code

SEXP dfm ,head,df , dfint , dfStr,lsnm;

*SEXP  valueVector[2];*

char *ab[3] = {"aa","vv","gy"};
int sn[3] ={99,89,12};
char *listnames[2] = {"int","string"};
int i,j;

//=

PROTECT(df = allocVector(VECSXP,2));

*PROTECT(valueVector[0] = allocVector(REALSXP,3));*
*PROTECT(valueVector[1] = allocVector(VECSXP,3));*


PROTECT(lsnm = allocVector(STRSXP,2));

SET_STRING_ELT(lsnm,0,mkChar("int"));
SET_STRING_ELT(lsnm,1,mkChar("string"));
SEXP rawvec,headr;
unsigned char str[24]="abcdef";

for ( i = 0 ; i < 3; i++ ) {

*SET_STRING_ELT(valueVector[1],i,mkChar(ab[i]));*
*REAL(valueVector[0])[i] = sn[i];*
}


It works , data frame is being created and executed properly .
Just curious , if I am doing anything wrong or is there another way around
for creation of data-frame .  I am concerned about the SEXP 2D array .

Thanks,
Sandip

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


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_GlobalEnv));


I tried the above following , it seemed to be not working . Can you please
help.



Can you elaborate? The above code works AFAICT ...


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 they
are still being evaluated.)


How true but who can blame him? The Writing R Extensions manual
contains the same mistake:

  SEXP mkans(double x)
  {
SEXP ans;
ans = PROTECT(allocVector(REALSXP, 1));
REAL(ans)[0] = x;
UNPROTECT(1);
return ans;
  }

  double feval(double x, SEXP f, SEXP rho)
  {
defineVar(install("x"), mkans(x), rho);
return REAL(eval(f, rho))[0];
  }

Reported here more than 6 years ago and never fixed:

  https://stat.ethz.ch/pipermail/r-devel/2008-January/048040.html

Cheers,
H.



Now, I'm not sure this is the source of the actual problem, since both
"data.frame" and "head" presumably already exist, so the install won't
actually allocate memory.  But this is not a safe coding method in
general.

Radford Neal

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel



--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpa...@fhcrc.org
Phone:  (206) 667-5791
Fax:(206) 667-1319

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Compiling R-3.1.0 on debian with libpng/libjpeg

2014-06-26 Thread Dirk Eddelbuettel

On 26 June 2014 at 12:10, Prof Brian Ripley wrote:
| On 26/06/2014 07:46, Preussner, Jens wrote:
| > Dear r-developers,
| >
| > I currently face an issue while compiling R from source on a debian wheezy. 
When running the configure script (particularly with --enable-R-shlib 
--prefix=/packages/R/3.1.0/) I get a Makefile and the output
| > ...
| >Interfaces supported:  X11
| >External libraries:readline
| >Additional capabilities:   PNG, JPEG, NLS
| >Options enabled:   shared R library, shared BLAS, R profiling
| > ...
| >
| > After compiling and checking the capabilities, R tells me the following:
| >> capabilities()
| >  jpeg  png tifftcltk  X11 aqua http/ftp  sockets
| > FALSEFALSEFALSEFALSEFALSEFALSE TRUE TRUE
| >libxml fifo   clediticonv  NLS  profmemcairo
| >  TRUE TRUE TRUE TRUE TRUEFALSEFALSE
| >
| > I already have R on another machine with jpeg/png capabilities, also 
compiled on my own. I crosschecked the versions of the libpng-* and libjpeg-* 
packages installed there and could not find any difference. Also returning to 
R-3.0.2 doesn't work.
| > A last thing: The same question came up back in 2009, but there was no 
answer on the list.. 
https://stat.ethz.ch/pipermail/r-help/2009-December/222967.html
| >
| > Any suggestions how to get more information on what is going on here?
| 
| As you do not have capabilities for cairo nor X11, read ?png, e.g.
| 
|  type: character string, one of ‘"Xlib"’ or ‘"quartz"’ (some OS X
|builds) or ‘"cairo"’.  The latter will only be available if
|the system was compiled with support for cairo - otherwise
|‘"Xlib"’ will be used.  The default is set by
|‘getOption("bitmapType")’ - the ‘out of the box’ default is
|‘"quartz"’ or ‘"cairo"’ where available, otherwise ‘"Xlib"’.
| 
|   R can be compiled without support for some or all of the types for
|   each of these devices: this will be reported if you attempt to use
|   them on a system where they are not supported.  For ‘type =
|   "Xlib"’ they may not be usable unless the X11 display is available
|   to the owner of the R process.
| 
| So, the only type available to you appears to be "Xlib", and that 
| process does not have access to an X server.
| 
| The strongly recommended solution is to get cairographics working: see
| 
http://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Useful-libraries-and-programs

1)  Here are the Build-Depends: the actual Debian binary uses:

Build-Depends: gcc (>= 4:4.1.0), g++ (>= 4:4.1.0), gfortran (>= 4:4.1.0),
libblas-dev, liblapack-dev (>= 3.1.1), tcl8.5-dev, tk8.5-dev, bison,
groff-base, libncurses5-dev, libreadline-dev, debhelper (>= 7.2.3),
texinfo (>= 4.1-2), libbz2-dev, liblzma-dev, libpcre3-dev, xdg-utils,
zlib1g-dev, libpng-dev, libjpeg-dev, libx11-dev, libxt-dev,
x11proto-core-dev, libpango1.0-dev, libcairo2-dev, libtiff5-dev, xvfb,
xauth, xfonts-base, texlive-base, texlive-latex-base,
texlive-generic-recommended, texlive-fonts-recommended,
texlive-fonts-extra, texlive-extra-utils, texlive-latex-recommended,
texlive-latex-extra, default-jdk [!arm !hppa !kfreebsd-i386
!kfreebsd-amd64 !hurd-i386], mpack, bash-completion

2)  Here is the relevant part from debian/rules calling configure:

./configure --prefix=/usr   \
--with-cairo\
--with-jpeglib  \
--with-readline \
--with-tcltk\
--with-system-bzlib \
--with-system-pcre  \
--with-system-zlib  \
--mandir=/usr/share/man \
--infodir=/usr/share/info   \
--datadir=/usr/share/R/share\
--includedir=/usr/share/R/include   \
$(atlas)\
$(lapack)   \
--enable-R-profiling\
--enable-R-shlib\
--enable-memory-profiling   \
--without-recommended-packages  \
--build $(buildarch)

We select Cairo and Jpeg, Png gets autoselected when the header and
library are found.

3)  None of this is secret. Our package sources have always been public.

Greetings from DSC,  Dirk

| 
| > Many thanks and best regards,
| >
| > Jens
| >
| >
| > [[alternative HTML version deleted]]
| >
| > __
| > R-devel@r-project.org mailing list
| > https://stat.ethz.ch/mailman/listinfo/r-devel
| >
| 
| 
| -- 
| Brian D. Ripley,  

Re: [Rd] using 2D array of SEXP for creating dataframe

2014-06-26 Thread Hervé Pagès

Hi,

On 06/26/2014 02:32 PM, Sandip Nandi wrote:

Hi ,

For our production package i need to create a dataframein C . So I wrote
the following code

SEXP dfm ,head,df , dfint , dfStr,lsnm;

*SEXP  valueVector[2];*

char *ab[3] = {"aa","vv","gy"};
int sn[3] ={99,89,12};
char *listnames[2] = {"int","string"};
int i,j;

//=

PROTECT(df = allocVector(VECSXP,2));

*PROTECT(valueVector[0] = allocVector(REALSXP,3));*
*PROTECT(valueVector[1] = allocVector(VECSXP,3));*


PROTECT(lsnm = allocVector(STRSXP,2));

SET_STRING_ELT(lsnm,0,mkChar("int"));
SET_STRING_ELT(lsnm,1,mkChar("string"));
SEXP rawvec,headr;
unsigned char str[24]="abcdef";

for ( i = 0 ; i < 3; i++ ) {

*SET_STRING_ELT(valueVector[1],i,mkChar(ab[i]));*
*REAL(valueVector[0])[i] = sn[i];*
}


It works , data frame is being created and executed properly .


Really? You mean, you can compile this code right? Otherwise it's
incomplete: you allocate but do nothing with 'df'. Same with 'lsnm'.
And you don't UNPROTECT. With no further treatment, 'df' will be an
unnamed list containing junk data, but not the data.frame you expect.
So there are a few gaps that would need to be filled before this code
actually works as intended.

Maybe try and come back again with specific questions?

Cheers,
H.
 > Just curious , if I am doing anything wrong or is there another way 
around

for creation of data-frame .  I am concerned about the SEXP 2D array .

Thanks,
Sandip

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel



--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpa...@fhcrc.org
Phone:  (206) 667-5791
Fax:(206) 667-1319

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] using 2D array of SEXP for creating dataframe

2014-06-26 Thread Sandip Nandi
Hi ,

I have put incomplete code here . The complete code works , My doubt is ,
what I am doing logical/safe ? Any memory leak going to happen ? is there
any way to create dataframe ?



SEXP formDF() {

SEXP dfm ,head,df , dfint , dfStr,lsnm;
SEXP  valueVector[2];
char *ab[3] = {"aa","vv","gy"};
int sn[3] ={99,89,12};
char *listnames[2] = {"int","string"};
int i,j;

PROTECT(df = allocVector(VECSXP,2));

PROTECT(valueVector[0] = allocVector(REALSXP,3));
PROTECT(valueVector[1] = allocVector(VECSXP,3));
PROTECT(lsnm = allocVector(STRSXP,2));

SET_STRING_ELT(lsnm,0,mkChar("int"));
SET_STRING_ELT(lsnm,1,mkChar("string"));
SEXP rawvec,headr;

for ( i = 0 ; i < 3; i++ ) {
SET_STRING_ELT(valueVector[1],0,mkChar(listNames[i]));
REAL(valueVector[0])[i] = sn[i];
}

SET_VECTOR_ELT(df,1,valueVector[0]);
SET_VECTOR_ELT(df,0,valueVector[1]);
setAttrib(df,R_RowNamesSymbol,lsnm);

PROTECT(dfm=lang3(install("data.frame"),df,ScalarLogical(FALSE)));
SET_TAG(CDDR(dfm), install("stringsAsFactors")) ;
SEXP res = PROTECT(eval(dfm,R_GlobalEnv));

UNPROTECT(7);
return res;

}



On Thu, Jun 26, 2014 at 3:49 PM, Hervé Pagès  wrote:

> Hi,
>
>
> On 06/26/2014 02:32 PM, Sandip Nandi wrote:
>
>> Hi ,
>>
>> For our production package i need to create a dataframein C . So I wrote
>> the following code
>>
>> SEXP dfm ,head,df , dfint , dfStr,lsnm;
>>
>> *SEXP  valueVector[2];*
>>
>>
>> char *ab[3] = {"aa","vv","gy"};
>> int sn[3] ={99,89,12};
>> char *listnames[2] = {"int","string"};
>> int i,j;
>>
>> //=
>>
>> PROTECT(df = allocVector(VECSXP,2));
>>
>> *PROTECT(valueVector[0] = allocVector(REALSXP,3));*
>> *PROTECT(valueVector[1] = allocVector(VECSXP,3));*
>>
>>
>>
>> PROTECT(lsnm = allocVector(STRSXP,2));
>>
>> SET_STRING_ELT(lsnm,0,mkChar("int"));
>> SET_STRING_ELT(lsnm,1,mkChar("string"));
>> SEXP rawvec,headr;
>> unsigned char str[24]="abcdef";
>>
>> for ( i = 0 ; i < 3; i++ ) {
>>
>> *SET_STRING_ELT(valueVector[1],i,mkChar(ab[i]));*
>> *REAL(valueVector[0])[i] = sn[i];*
>>
>> }
>>
>>
>> It works , data frame is being created and executed properly .
>>
>
> Really? You mean, you can compile this code right? Otherwise it's
> incomplete: you allocate but do nothing with 'df'. Same with 'lsnm'.
> And you don't UNPROTECT. With no further treatment, 'df' will be an
> unnamed list containing junk data, but not the data.frame you expect.
> So there are a few gaps that would need to be filled before this code
> actually works as intended.
>
> Maybe try and come back again with specific questions?
>
> Cheers,
> H.
>
>  > Just curious , if I am doing anything wrong or is there another way
> around
>
>> for creation of data-frame .  I am concerned about the SEXP 2D array .
>>
>> Thanks,
>> Sandip
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>>
> --
> Hervé Pagès
>
> Program in Computational Biology
> Division of Public Health Sciences
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N, M1-B514
> P.O. Box 19024
> Seattle, WA 98109-1024
>
> E-mail: hpa...@fhcrc.org
> Phone:  (206) 667-5791
> Fax:(206) 667-1319
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] using 2D array of SEXP for creating dataframe

2014-06-26 Thread Hervé Pagès

Hi Sandip,

On 06/26/2014 04:21 PM, Sandip Nandi wrote:

Hi ,

I have put incomplete code here . The complete code works , My doubt is
, what I am doing logical/safe ? Any memory leak going to happen ? is
there any way to create dataframe ?


I still don't believe it "works". It doesn't even compile. More below...





SEXP formDF() {

SEXP dfm ,head,df , dfint , dfStr,lsnm;
SEXP  valueVector[2];
char *ab[3] = {"aa","vv","gy"};
int sn[3] ={99,89,12};
char *listnames[2] = {"int","string"};
int i,j;

PROTECT(df = allocVector(VECSXP,2));

PROTECT(valueVector[0] = allocVector(REALSXP,3));
PROTECT(valueVector[1] = allocVector(VECSXP,3));
PROTECT(lsnm = allocVector(STRSXP,2));

SET_STRING_ELT(lsnm,0,mkChar("int"));
SET_STRING_ELT(lsnm,1,mkChar("string"));
SEXP rawvec,headr;

for ( i = 0 ; i < 3; i++ ) {
SET_STRING_ELT(valueVector[1],0,mkChar(listNames[i]));


'listNames' is undeclared (C is case-sensitive).

Let's assume you managed to compile this with an (imaginary)
case-insensitive C compiler, 'listnames' is an array of length
2 and this for loop tries to read the 3 first elements
from it. So you're just lucky that you didn't get a segfault.
In any case, I don't see how this code could produce
the data.frame you're trying to make.

If you want to discuss how to improve code that *works* (i.e.
compiles and produces the expected result), that's fine, but you
should be able to show that code. Otherwise it sounds like you're
asking people to fix your code. Or to write it for you. Maybe
that's fine too but people will be more sympathetic and willing
to help if you're honest about it.

Cheers,
H.


REAL(valueVector[0])[i] = sn[i];
}

SET_VECTOR_ELT(df,1,valueVector[0]);
SET_VECTOR_ELT(df,0,valueVector[1]);
setAttrib(df,R_RowNamesSymbol,lsnm);

PROTECT(dfm=lang3(install("data.frame"),df,ScalarLogical(FALSE)));
SET_TAG(CDDR(dfm), install("stringsAsFactors")) ;
SEXP res = PROTECT(eval(dfm,R_GlobalEnv));

UNPROTECT(7);
return res;

}



On Thu, Jun 26, 2014 at 3:49 PM, Hervé Pagès mailto:hpa...@fhcrc.org>> wrote:

Hi,


On 06/26/2014 02:32 PM, Sandip Nandi wrote:

Hi ,

For our production package i need to create a dataframein C . So
I wrote
the following code

SEXP dfm ,head,df , dfint , dfStr,lsnm;

*SEXP  valueVector[2];*


char *ab[3] = {"aa","vv","gy"};
int sn[3] ={99,89,12};
char *listnames[2] = {"int","string"};
int i,j;

//__=

PROTECT(df = allocVector(VECSXP,2));

*PROTECT(valueVector[0] = allocVector(REALSXP,3));*
*PROTECT(valueVector[1] = allocVector(VECSXP,3));*



PROTECT(lsnm = allocVector(STRSXP,2));

SET_STRING_ELT(lsnm,0,mkChar("__int"));
SET_STRING_ELT(lsnm,1,mkChar("__string"));
SEXP rawvec,headr;
unsigned char str[24]="abcdef";

for ( i = 0 ; i < 3; i++ ) {

*SET_STRING_ELT(valueVector[1]__,i,mkChar(ab[i]));*
*REAL(valueVector[0])[i] = sn[i];*

}


It works , data frame is being created and executed properly .


Really? You mean, you can compile this code right? Otherwise it's
incomplete: you allocate but do nothing with 'df'. Same with 'lsnm'.
And you don't UNPROTECT. With no further treatment, 'df' will be an
unnamed list containing junk data, but not the data.frame you expect.
So there are a few gaps that would need to be filled before this code
actually works as intended.

Maybe try and come back again with specific questions?

Cheers,
H.

  > Just curious , if I am doing anything wrong or is there another
way around

for creation of data-frame .  I am concerned about the SEXP 2D
array .

Thanks,
Sandip

 [[alternative HTML version deleted]]


R-devel@r-project.org  mailing list
https://stat.ethz.ch/mailman/__listinfo/r-devel



--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpa...@fhcrc.org 
Phone: (206) 667-5791 
Fax: (206) 667-1319 




--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpa...@fhcrc.org
Phone:  (206) 667-5791
Fax:(206) 667-1319

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] using 2D array of SEXP for creating dataframe

2014-06-26 Thread Sandip Nandi
Hi ,

I have asked a question , whether the data structure I am using to create a
dataframe is fine or there is anyother way i can use. My aim is to read  a
database and write it to dataframe and do operation on it . The dataframe
creation ,output everything works .  The code I put is wrong , trying to
adding pieces and do it ,sorry for that.I feel my way of doing ,
creating a 2D array may not be the best, so if someone can point out any
drawback of my method will be great . My code in production can read 100k
rows and write in 15 seconds . But one case , when I try to assign NA_REAL
to a real vector it causes floating point exception. So I doubt something
is not wrong . People may be doing faster,efficient way.

This is a sample code
*/**

*dfm is a dataframe which i assume as list of list . So I created a SEXP
array valueVector[2]  where each one can hold different datatype .  Now
values are assigned and dataframe is generated at end*

**/*

SEXP formDF() {

SEXP dfm ,head,df , dfint , dfStr,lsnm;
SEXP  valueVector[2];
char *ab[3] = {"aa","vv","gy"};
int sn[3] ={99,89,12};
char *listnames[2] = {"int","string"};
int i,j;


PROTECT(valueVector[0] = allocVector(REALSXP,3));
PROTECT(valueVector[1] = allocVector(STRSXP,3));
PROTECT(lsnm = allocVector(STRSXP,2));

SET_STRING_ELT(lsnm,0,mkChar("int"));
SET_STRING_ELT(lsnm,1,mkChar("string"));

for ( i = 0 ; i < 3; i++ ) {
SET_STRING_ELT(valueVector[1],i,mkChar(ab[i]));
REAL(valueVector[0])[i] = sn[i];
}


SET_VECTOR_ELT(df,1,valueVector[0]);
SET_VECTOR_ELT(df,0,valueVector[1]);
setAttrib(df,R_RowNamesSymbol,lsnm);

PROTECT(dfm=lang3(install("data.frame"),df,ScalarLogical(FALSE)));
SET_TAG(CDDR(dfm), install("stringsAsFactors")) ;
SEXP res = PROTECT(eval(dfm,R_GlobalEnv));

UNPROTECT(7);
return res;

}


On Thu, Jun 26, 2014 at 4:52 PM, Hervé Pagès  wrote:

> Hi Sandip,
>
>
> On 06/26/2014 04:21 PM, Sandip Nandi wrote:
>
>> Hi ,
>>
>> I have put incomplete code here . The complete code works , My doubt is
>> , what I am doing logical/safe ? Any memory leak going to happen ? is
>> there any way to create dataframe ?
>>
>
> I still don't believe it "works". It doesn't even compile. More below...
>
>
>
>>
>>
>> SEXP formDF() {
>>
>> SEXP dfm ,head,df , dfint , dfStr,lsnm;
>> SEXP  valueVector[2];
>> char *ab[3] = {"aa","vv","gy"};
>> int sn[3] ={99,89,12};
>> char *listnames[2] = {"int","string"};
>> int i,j;
>>
>> PROTECT(df = allocVector(VECSXP,2));
>>
>> PROTECT(valueVector[0] = allocVector(REALSXP,3));
>> PROTECT(valueVector[1] = allocVector(VECSXP,3));
>> PROTECT(lsnm = allocVector(STRSXP,2));
>>
>> SET_STRING_ELT(lsnm,0,mkChar("int"));
>> SET_STRING_ELT(lsnm,1,mkChar("string"));
>> SEXP rawvec,headr;
>>
>> for ( i = 0 ; i < 3; i++ ) {
>> SET_STRING_ELT(valueVector[1],0,mkChar(listNames[i]));
>>
>
> 'listNames' is undeclared (C is case-sensitive).
>
> Let's assume you managed to compile this with an (imaginary)
> case-insensitive C compiler, 'listnames' is an array of length
> 2 and this for loop tries to read the 3 first elements
> from it. So you're just lucky that you didn't get a segfault.
> In any case, I don't see how this code could produce
> the data.frame you're trying to make.
>
> If you want to discuss how to improve code that *works* (i.e.
> compiles and produces the expected result), that's fine, but you
> should be able to show that code. Otherwise it sounds like you're
> asking people to fix your code. Or to write it for you. Maybe
> that's fine too but people will be more sympathetic and willing
> to help if you're honest about it.
>
> Cheers,
> H.
>
>  REAL(valueVector[0])[i] = sn[i];
>> }
>>
>> SET_VECTOR_ELT(df,1,valueVector[0]);
>> SET_VECTOR_ELT(df,0,valueVector[1]);
>> setAttrib(df,R_RowNamesSymbol,lsnm);
>>
>> PROTECT(dfm=lang3(install("data.frame"),df,ScalarLogical(FALSE)));
>> SET_TAG(CDDR(dfm), install("stringsAsFactors")) ;
>> SEXP res = PROTECT(eval(dfm,R_GlobalEnv));
>>
>> UNPROTECT(7);
>> return res;
>>
>> }
>>
>>
>>
>> On Thu, Jun 26, 2014 at 3:49 PM, Hervé Pagès > > wrote:
>>
>> Hi,
>>
>>
>> On 06/26/2014 02:32 PM, Sandip Nandi wrote:
>>
>> Hi ,
>>
>> For our production package i need to create a dataframein C . So
>> I wrote
>> the following code
>>
>> SEXP dfm ,head,df , dfint , dfStr,lsnm;
>>
>> *SEXP  valueVector[2];*
>>
>>
>> char *ab[3] = {"aa","vv","gy"};
>> int sn[3] ={99,89,12};
>> char *listnames[2] = {"int","string"};
>> int i,j;
>>
>> //__=
>>
>>
>> PROTECT(df = allocVector(VECSXP,2));
>>
>> *PROTECT(valueVector[0] = allocVector(REALSXP,3));*
>> *PROTECT(valueVector[1] = allocVector(VECSXP,3));*
>>
>>
>>
>> PROTECT(lsnm = allocVector(STRSXP,2));
>>
>> SET_STRING_ELT(lsnm,0,mkChar("__int"));
>> SET_STRING_ELT(lsnm,1,mkChar("__string"));
>>
>> SEXP rawvec,headr;
>> unsigned char str[24]="abcdef";
>>
>>

Re: [Rd] dget() much slower in recent R versions

2014-06-26 Thread Hervé Pagès



On 06/21/2014 12:56 AM, Prof Brian Ripley wrote:

On 20/06/2014 15:37, Ista Zahn wrote:

Hello,

I've noticed that dget() is much slower in the current and devel R
versions than in previous versions. In 2.15 reading a 1-row
data.frame takes less than half a second:


(which.r <- R.Version()$version.string)

[1] "R version 2.15.2 (2012-10-26)"

x <- data.frame(matrix(sample(letters, 10, replace = TRUE), ncol
= 10))
dput(x, which.r)
system.time(y <- dget(which.r))

user  system elapsed
   0.546   0.033   0.586

While in 3.1.0 and r-devel it takes around 7 seconds.


(which.r <- R.Version()$version.string)

[1] "R version 3.1.0 (2014-04-10)"

x <- data.frame(matrix(sample(letters, 10, replace = TRUE), ncol
= 10))
dput(x, which.r)
system.time(y <- dget(which.r))

user  system elapsed
   6.920   0.060   7.074


(which.r <- R.Version()$version.string)

[1] "R Under development (unstable) (2014-06-19 r65979)"

x <- data.frame(matrix(sample(letters, 10, replace = TRUE), ncol
= 10))
dput(x, which.r)
system.time(y <- dget(which.r))

user  system elapsed
   6.886   0.047   6.943




I know dput/dget is probably not the right tool for this job:
nevertheless the slowdown in quite dramatic so I thought it was worth
calling attention to.


This is completely the wrong way to do this. See ?dump.

dget() basically calls eval(parse()).  parse() is much slower in R >=
3.0 mainly because it keeps more information.  Using keep.source=FALSE
here speeds things up a lot.

 > system.time(y <- dget(which.r))
user  system elapsed
   3.233   0.012   3.248
 > options(keep.source=FALSE)
 > system.time(y <- dget(which.r))
user  system elapsed
   0.090   0.001   0.092


Nice. But why add the 'keep.source' arg do dget() in R-devel rev 65990:

  dget <- function(file, keep.source = FALSE)
  eval(parse(file = file, keep.source = FALSE))

(Note that the 'keep.source' arg is actually ignored.)

Why not just:

  dget <- function(file)
  eval(parse(file = file, keep.source = FALSE))

Cheers,

H.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] using 2D array of SEXP for creating dataframe

2014-06-26 Thread Hervé Pagès

On 06/26/2014 05:18 PM, Sandip Nandi wrote:

Hi ,

I have asked a question , whether the data structure I am using to
create a dataframe is fine or there is anyother way i can use. My aim is
to read  a database and write it to dataframe and do operation on it .
The dataframe creation ,output everything works .  The code I put is
wrong , trying to adding pieces and do it ,sorry for that.I feel my
way of doing , creating a 2D array may not be the best, so if someone
can point out any drawback of my method will be great . My code in
production can read 100k rows and write in 15 seconds . But one case ,
when I try to assign NA_REAL to a real vector it causes floating point
exception. So I doubt something is not wrong . People may be doing
faster,efficient way.



Please understand that the code you send is useful for the discussion
only if we can understand it. And for this it needs to make sense.
The code below still makes little sense. Did you try it? For example
you're calling SET_VECTOR_ELT() and setAttrib() on an SEXP ('df') that
you didn't even allocate. Sounds maybe like a detail but because of
that the code will segfault and, more importantly, it's not clear what
kind of SEXP you want 'df' to be.

Also the following line makes no sense:

  setAttrib(df,R_RowNamesSymbol,lsnm);

given that 'lsnm' is c("int", "string") so it looks more like the col
names than the row names (and also because you're apparently trying to
make a 3x2 data.frame, not a 2x2).

Anyway, once you realize that a data.frame is just a list with 3
attributes:

  > attributes(data.frame(int=c(99,89,12), string=c("aa", "vv", "gy")))
  $names
  [1] "int""string"

  $row.names
  [1] 1 2 3

  $class
  [1] "data.frame"

everything becomes simple at the C level i.e. just make that list
and stick these 3 attributes on it. You don't need to call R code
from C (which BTW will protect you from random changes in the behavior
of the data.frame() constructor). You don't need the intermediate
'valueVector' data structure (what you seem to be referring to as the
"2D array of SEXP", don't know why, doesn't look like a 2D array to me,
but you never explained).

Cheers,
H.



This is a sample code
*/**
*
*
*dfm is a dataframe which i assume as list of list . So I created a SEXP
array valueVector[2]  where each one can hold different datatype .  Now
values are assigned and dataframe is generated at end*
*
*
**/*

SEXP formDF() {

SEXP dfm ,head,df , dfint , dfStr,lsnm;
SEXP  valueVector[2];
char *ab[3] = {"aa","vv","gy"};
int sn[3] ={99,89,12};
char *listnames[2] = {"int","string"};
int i,j;


PROTECT(valueVector[0] = allocVector(REALSXP,3));
PROTECT(valueVector[1] = allocVector(STRSXP,3));
PROTECT(lsnm = allocVector(STRSXP,2));

SET_STRING_ELT(lsnm,0,mkChar("int"));
SET_STRING_ELT(lsnm,1,mkChar("string"));

for ( i = 0 ; i < 3; i++ ) {
SET_STRING_ELT(valueVector[1],i,mkChar(ab[i]));
REAL(valueVector[0])[i] = sn[i];
}


SET_VECTOR_ELT(df,1,valueVector[0]);
SET_VECTOR_ELT(df,0,valueVector[1]);
setAttrib(df,R_RowNamesSymbol,lsnm);

PROTECT(dfm=lang3(install("data.frame"),df,ScalarLogical(FALSE)));
SET_TAG(CDDR(dfm), install("stringsAsFactors")) ;
SEXP res = PROTECT(eval(dfm,R_GlobalEnv));

UNPROTECT(7);
return res;

}


On Thu, Jun 26, 2014 at 4:52 PM, Hervé Pagès mailto:hpa...@fhcrc.org>> wrote:

Hi Sandip,


On 06/26/2014 04:21 PM, Sandip Nandi wrote:

Hi ,

I have put incomplete code here . The complete code works , My
doubt is
, what I am doing logical/safe ? Any memory leak going to happen
? is
there any way to create dataframe ?


I still don't believe it "works". It doesn't even compile. More below...





SEXP formDF() {

SEXP dfm ,head,df , dfint , dfStr,lsnm;
SEXP  valueVector[2];
char *ab[3] = {"aa","vv","gy"};
int sn[3] ={99,89,12};
char *listnames[2] = {"int","string"};
int i,j;

PROTECT(df = allocVector(VECSXP,2));

PROTECT(valueVector[0] = allocVector(REALSXP,3));
PROTECT(valueVector[1] = allocVector(VECSXP,3));
PROTECT(lsnm = allocVector(STRSXP,2));

SET_STRING_ELT(lsnm,0,mkChar("__int"));
SET_STRING_ELT(lsnm,1,mkChar("__string"));
SEXP rawvec,headr;

for ( i = 0 ; i < 3; i++ ) {
SET_STRING_ELT(valueVector[1],__0,mkChar(listNames[i]));


'listNames' is undeclared (C is case-sensitive).

Let's assume you managed to compile this with an (imaginary)
case-insensitive C compiler, 'listnames' is an array of length
2 and this for loop tries to read the 3 first elements
from it. So you're just lucky that you didn't get a segfault.
In any case, I don't see how this code could produce
the data.frame you're trying to make.

If you want to discuss how to improve code that *works* (i.e.
compiles and produces the expected result), that's fine, but you
should be able to show that code. Otherwise it sounds like you're
as

[Rd] Listing Packages in Depends or Imports

2014-06-26 Thread Dario Strbenac
Hello,

The Writing R Extensions manual gives confusing advice. Compare 

Packages listed in imports or importFrom directives in the NAMESPACE file 
should almost always be in ‘Imports’ and not ‘Depends’. 

with 

Almost always packages mentioned in ‘Depends’ should also be imported from in 
the NAMESPACE file

--
Dario Strbenac
PhD Student
University of Sydney
Camperdown NSW 2050
Australia

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel