[Rd] cleanup temporary directory

2014-09-17 Thread Sandip Nandi
Hi ,

When a R session runs , it creates a temporary directory . I am using
 R_CleanTempDir() to clean it up . It looks like its not working properly .


So what exactly is going on here is , my example is

main()

start__R__Interpreter

while(1)

{

execute R scripts  using R_parseVector  and R_tryEval . .
break;
}


R_cleanup_tempDir()
R_session_End()


So is the Rtemp directory created in every R_Tryeval call ? The R temporary
file looks like this

RtmpzgKWqU:
RtmpzieK01:
RtmpzleSGb:
RtmpzqlvWS:


Thanks,
Sandip

[[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-27 Thread Sandip Nandi
Thanks a lot .  Appreciate your time . I am sorry for missing snippets of
the code , trying to copy back and forth . My bad .sorry for that .

The dataframe df is to be of VECSXP .
PROTECT(df = allocVector(VECSXP,2));

What I am trying to do ?

Lets say you read a huge table , with each column is different datatype
some integer , some real,some string , some raw . And you have to return  a
dataframe after reading it . So what I did lets create a array of SEXP (
SEXP dataframevalues[noOfCols] ) . Now from table each column is read and
also the datatype is obtained. I allocate each array with number of values
to be inserted .

Now there is one outer vector of type VECSXP , which will hold the
dataframe[noOfCols] . So VECSXP is of  length noOfCols.
. After that a R internal call is performed to convert it to a data frame
format .


And yes , i want to set for column Names, not row names.
Thanks,



On Thu, Jun 26, 2014 at 6:35 PM, Hervé Pagès hpa...@fhcrc.org wrote:

 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] intstring

   $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 hpa...@fhcrc.org
 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

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 simon.urba...@r-project.org
 wrote:

 On Jun 25, 2014, at 11:31 PM, Sandip Nandi sanna...@umail.iu.edu 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 sanna...@umail.iu.edu 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 sanna...@umail.iu.edu 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
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 radf...@cs.toronto.edu
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 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 radf...@cs.toronto.edu
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] 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 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


[[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 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 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
 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 hpa...@fhcrc.org
 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

[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,ScalarInteger(1)));
head  = PROTECT(eval(head,R_GlobalEnv));


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

Thanks

[[alternative HTML version deleted]]

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


[Rd] backtrace while trying to clear workspace

2014-05-02 Thread Sandip Nandi
Hi ,

I tried to do the following . Before I execute the R script , i tried to
clear the work space using
rm(list = ls(all = TRUE)); . I get the following back trace . Its a huge
backtrace , attached a part of it . Can anyone help why I get this ?


#13 0x2afd612f in Rf_eval (e=0x1448d68, rho=0x16c6780) at eval.c:399
#14 0x2afdabf6 in Rf_applyClosure (call=0x1447108, op=0x1448f60,
arglist=0x16c6860, rho=0x16c6a20, suppliedenv=0x53ddc8) at eval.c:861
#15 0x2afd621b in Rf_eval (e=0x1447108, rho=0x16c6a20) at eval.c:512
---Type return to continue, or q return to quit---
#16 0x2afd787f in Rf_DispatchOrEval (call=0x1447178, op=0x5154a0,
generic=0x2b17b54b $, args=0x16c6908, rho=0x16c6a20,
ans=0x7fffd2c0, dropmissing=0, argsevald=0) at eval.c:2311
#17 0x2b095937 in do_subset3 (call=0x1447178, op=0x5154a0,
args=0x16c6908, env=0x16c6a20) at subset.c:1068
#18 0x2afcd946 in bcEval (body=value optimized out,
rho=0x16c6a20,
useCache=2873058336) at eval.c:4482
#19 0x2afd612f in Rf_eval (e=0x14463d0, rho=0x16c6a20) at eval.c:399
#20 0x2afdabf6 in Rf_applyClosure (call=0x16c6c50, op=0x1446638,
arglist=0x16c6b70, rho=0x53dd90, suppliedenv=0x53ddc8) at eval.c:861
#21 0x2afd621b in Rf_eval (e=0x16c6c50, rho=0x53dd90) at eval.c:512
#22 0x2af8738e in protectedEval (d=value optimized out)
at context.c:747
#23 0x2af87cfe in R_ToplevelExec (fun=0x2af87370
protectedEval,
data=0x7fffde00) at context.c:702
#24 0x2af87d89 in R_tryEval (e=value optimized out,
env=value optimized out, ErrorOccurred=0x61) at context.c:761
#25 0x2adeb109 in executeText (
prog=0x7fffe0a0 *rm(list = ls(all = TRUE));*,


Thanks

[[alternative HTML version deleted]]

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


[Rd] question regarding lang2 command in C

2014-04-02 Thread Sandip Nandi
Hi ,

I am asking too many questions , sorry for that .  I am creating a data
frame in C itself , reading a table .

The data frame calling code looks like this
==

*PROTECT(dfm=lang2(install(data.frame),df));*
*SEXP res = PROTECT(eval(dfm,R_GlobalEnv));*

UNPROTECT(2);
return res;
==

It works fine , now the problem is I want to do the below one  from C
itself  ( adding the *stringsAsFactors = FALSE* parameter)

df - data.frame(gender, age, *stringsAsFactors = FALSE*);

How can I do it from C , adding extra parameters. Anyone has pointer or any
example . It will be great help. I find the arguments will always be in
pair , i don't find any example.


I try to see the source code ,not able to make it

Thanks

[[alternative HTML version deleted]]

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


[Rd] Typeof for character vector in dataframe returns integer

2014-04-01 Thread Sandip Nandi
Hi ,

I want to know is this behavior expected and why is that ? Need some help

 gender - c(F, M, M, F, F, M, F, F)
 age- c(23, 25, 27, 29, 31, 33, 35, 37)
 df- data.frame(gender,age)
 typeof(df[[1]])
[1] integer Why is this integer . *Should not it be
character ?*
 typeof(df[[2]])
[1] double

 typeof(gender)
[1] character
 typeof(age)
[1] double


In my code i am trying to do some thing based on typeof and the type for
character column is strange.

Thanks,
Sandip

[[alternative HTML version deleted]]

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


Re: [Rd] Typeof for character vector in dataframe returns integer

2014-04-01 Thread Sandip Nandi
Hi ,

I am concerned about the return value of typeof in character column in a
dataframe. I expect it to be of character ,it returns integer instead .

Thanks




On Tue, Apr 1, 2014 at 5:56 PM, Joshua Ulrich josh.m.ulr...@gmail.comwrote:


 On Apr 1, 2014 7:48 PM, Sandip Nandi sanna...@umail.iu.edu wrote:
 
  Hi ,
 
  I want to know is this behavior expected and why is that ? Need some help
 
   gender - c(F, M, M, F, F, M, F, F)
   age- c(23, 25, 27, 29, 31, 33, 35, 37)
   df- data.frame(gender,age)
   typeof(df[[1]])
  [1] integer Why is this integer . *Should not it be
  character ?*
   typeof(df[[2]])
  [1] double
 
   typeof(gender)
  [1] character
   typeof(age)
  [1] double
  
 
  In my code i am trying to do some thing based on typeof and the type for
  character column is strange.
 
 The first column is coerced to factor when stringsAsFactors=TRUE, which is
 the default for data.frame. See ?data.frame.

  Thanks,
  Sandip
 
  [[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] C API to get numrow of data frame

2014-03-31 Thread Sandip Nandi
Hi ,

Is there any C API to the R API  nrow of dataframe ?

x- data.frame()
n- nrow(x)
print(n)
0


Example :
My C function which deals with data frame looks like and I don't to send
the  number of rows of data frame .I want to detect it from the function
itself, my function take data frame as argument and do some on it. I want
API equivalent to nrow. I tried Rf_nrows,Rf_ncols . No much help.

SEXP  writeRR(SEXP dataframe) {

}


Any help is very appreciated.

Thanks,
Sandip

[[alternative HTML version deleted]]

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


Re: [Rd] C API to get numrow of data frame

2014-03-31 Thread Sandip Nandi
The Rf_length(dataframe) will provide the length of row names . So it
should be checked first. I found one edge case now

My dataframe has 0 rows and 0 columns
  int num_rows = Rf_length(VECTOR_ELT(dataframe, 0));   returns 1
,in stead of 0 . Not sure why.

Thanks


On Mon, Mar 31, 2014 at 6:12 PM, Gábor Csárdi csardi.ga...@gmail.comwrote:

 I think it is actually better to check the length of the row names. In
 case the data frame has zero columns. (FIXME, of course.)

 Gabor


 On Mon, Mar 31, 2014 at 8:04 PM, Murray Stokely mur...@stokely.orgwrote:

 The simplest case would be:

int num_rows = Rf_length(VECTOR_ELT(dataframe, 0));
int num_columns = Rf_length(dataframe);

 There may be edge cases for which this doesn't work; would need to
 look into how the dim primitive is implemented to be sure.

- Murray


 On Mon, Mar 31, 2014 at 4:40 PM, Sandip Nandi sanna...@umail.iu.edu
 wrote:
  Hi ,
 
  Is there any C API to the R API  nrow of dataframe ?
 
  x- data.frame()
  n- nrow(x)
  print(n)
  0
 
 
  Example :
  My C function which deals with data frame looks like and I don't to send
  the  number of rows of data frame .I want to detect it from the function
  itself, my function take data frame as argument and do some on it. I
 want
  API equivalent to nrow. I tried Rf_nrows,Rf_ncols . No much help.
 
  SEXP  writeRR(SEXP dataframe) {
 
  }
 
 
  Any help is very appreciated.
 
  Thanks,
  Sandip
 
  [[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




[[alternative HTML version deleted]]

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


Re: [Rd] How to convert time_t to R date object

2014-03-16 Thread Sandip Nandi
Hi Bill ,

The following C code  may help you , time_t is typedef to long int

SEXP  getTime() {

  time_t current_time;
char* c_time_string;
current_time = time(NULL);
c_time_string = ctime(current_time);

   return mkString(c_time_String); // or if you want to return as int
vector return scalarInt(current_time);
}

If you feel anything wrong , I will be very happy to know .

Thanks,
Sandip


On Sun, Mar 16, 2014 at 9:54 PM, Bill Wang freecn...@gmail.com wrote:

 Hi Dirk,

 Thanks for your reply, I neede convert time_t to R type in C code, can not
 use Rcpp. Maybe Rcpp source code could help me.

 Cheers,
 Bill


 2014-03-16 22:55 GMT+08:00 Dirk Eddelbuettel e...@debian.org:

 
  On 16 March 2014 at 18:36, Bill Wang wrote:
  | I am writing a R extensions, and I need pass time_t to R in C, but I
  don't
  | know how to do.
  | Can you give me some help? do not use double directly.
 
  Just treat it as an int:
 
R library(Rcpp)
R cppFunction(Date time_t2date(time_t what) { return((int) what); })
R time_t2date(0)
[1] 1970-01-01
R time_t2date( Sys.Date() )
[1] 2014-03-16
R
 
 
  Here I use Rcpp to define the 'time_t2date' function on the fly.
 
  It takes the time_t and returns a Date type (which here is a C++ Date
 type
  mapping to the R Date -- you can ignore that, but will have to write the
  legwork yourself if you don't use Rcpp).
 
  As 'time_t' is 'long int' on my system, so I cast it to int. The rest is
  automagic (thanks to RcpP).
 
  Notice that I also get today's date down and up correctly.
 
  See 'Writing R Extensions' for the details at the C level.
 
  See the Rcpp documentation (and, if I may, my book) for details on Rcpp
 if
  that interests you.
 
  Dirk
 
  --
  Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com
 



 --

 *Travel | Programming*
 *http://freecnpro.net* http://freecnpro.net

 [[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] Create dataframe in C from table and return to R

2014-03-06 Thread Sandip Nandi
Hi ,

I am trying to create a dataframe in C and sebd it back to R.  Can anyone
point me to the part of the source code where it is doing ,  let me explain
the problem I am having .


My simple implementation is like this

SEXP formDF() {

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


PROTECT(df = allocVector(VECSXP,2));
PROTECT(dfint = allocVector(INTSXP,3));
PROTECT(dfStr = 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(dfStr,i,mkChar(ab[i]));
INTEGER(dfint)[i] = sn[i];
}
SET_VECTOR_ELT(df,0,dfint);
SET_VECTOR_ELT(df,1,dfStr);
setAttrib(df,R_NamesSymbol,lsnm);
//PROTECT(dfm=LCONS(dfm,list3(dfm,R_MissingArg,mkFalse(;

UNPROTECT(4);

dfm = PROTECT(lang2(install(data.frame),df));
SEXP res = PROTECT(eval(dfm,R_GlobalEnv));

UNPROTECT(2)

}


It works fine but i want it the other way

the output is
print(result)
  int string
1  99 aa
2  89 vv
3  12 gy


I want it in transposed . like

dft - as.data.frame(t(result))

*Can I do the transpose it from C itself ? Which part of code I should look
a*t .

What My objective ?

*Reading  rows of a table and create a dataframe out of it .  R is embedded
in database so cannot call the odbc .  Need to implement that part .
Database gives me API only to get a whole row at once .*

Thanks,
Sandip

[[alternative HTML version deleted]]

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


[Rd] What this error means

2014-02-25 Thread Sandip Nandi
Hi ,

I am running R from C using the interpreter . Now i
execute detach(package:td, unload=TRUE)
And I get the following error  . Any idea what it means ?


 *** caught segfault ***
address 0x102, cause 'memory not mapped'

Traceback:
 1: sys.parent()
 2: sys.function(sys.parent())
 3: formals(sys.function(sys.parent()))
 4: match.arg(event)
 5: packageEvent(pkgname, detach)
 6: exists(hookName, envir = .userHooksEnv, inherits = FALSE)
 7: getHook(packageEvent(pkgname, detach))
 8: detach(package:td, unload = TRUE)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace


Thanks,
Sandip

[[alternative HTML version deleted]]

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


Re: [Rd] What this error means

2014-02-25 Thread Sandip Nandi
Hi ,

I am using R_tryEval . Is there any way to handle the error ?

Thanks


On Tue, Feb 25, 2014 at 1:04 PM, Gabriel Becker gmbec...@ucdavis.eduwrote:

 Sandip,


 Are you doing R_eval (sp?) or R_tryEval? Uncaught R-level errors during
 C-level evaluation can cause segfaults IIRC.

 ~G


 On Tue, Feb 25, 2014 at 12:00 PM, Sandip Nandi sanna...@umail.iu.eduwrote:

 Hi ,

 I am running R from C using the interpreter . Now i
 execute detach(package:td, unload=TRUE)
 And I get the following error  . Any idea what it means ?


  *** caught segfault ***
 address 0x102, cause 'memory not mapped'

 Traceback:
  1: sys.parent()
  2: sys.function(sys.parent())
  3: formals(sys.function(sys.parent()))
  4: match.arg(event)
  5: packageEvent(pkgname, detach)
  6: exists(hookName, envir = .userHooksEnv, inherits = FALSE)
  7: getHook(packageEvent(pkgname, detach))
  8: detach(package:td, unload = TRUE)

 Possible actions:
 1: abort (with core dump, if enabled)
 2: normal R exit
 3: exit R without saving workspace
 4: exit R saving workspace


 Thanks,
 Sandip

 [[alternative HTML version deleted]]

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




 --
 Gabriel Becker
 Graduate Student
 Statistics Department
 University of California, Davis


[[alternative HTML version deleted]]

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


[Rd] How to set user read request while R install

2014-02-07 Thread Sandip Nandi
Hi ,

I have installed R on my system and the user access control looks like this

-rwxr-x*---* 1 root root 10578117 Feb  3 11:26 libR.so

I have installed R as root , but the access control for other is not
enabled by default ( at least Read option) .
 This can be solved using linux ways, but I am interested to know if there
is any way to mention while we run R or install R packages.

What I am trying to achieve ?

   We have multinode system , and some tool will install R and other
packages in all nodes. But the software which will access R run as
different user and not able to read . If R has some functionality while
installing , it can be performed easily else some manual work need to done.

Thanks,
Sandip

[[alternative HTML version deleted]]

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


Re: [Rd] How to set user read request while R install

2014-02-07 Thread Sandip Nandi
Thanks Simon ,

I will check it out .

Thanks,
Sandip


On Fri, Feb 7, 2014 at 11:16 AM, Simon Urbanek
simon.urba...@r-project.orgwrote:

 Sandip,

 this has nothing to do with R but rather your restrictive umask setting.
 If you want others to have rx permissions, change your umask to something
 like 0022 which is more commonly used (please see unix documentation on the
 concepts involved).

 Cheers,
 Simon


 On Feb 7, 2014, at 1:15 PM, Sandip Nandi sanna...@umail.iu.edu wrote:

  Hi ,
 
  I have installed R on my system and the user access control looks like
 this
 
  -rwxr-x*---* 1 root root 10578117 Feb  3 11:26 libR.so
 
  I have installed R as root , but the access control for other is not
  enabled by default ( at least Read option) .
  This can be solved using linux ways, but I am interested to know if there
  is any way to mention while we run R or install R packages.
 
  What I am trying to achieve ?
 
We have multinode system , and some tool will install R and other
  packages in all nodes. But the software which will access R run as
  different user and not able to read . If R has some functionality while
  installing , it can be performed easily else some manual work need to
 done.
 
  Thanks,
  Sandip
 
[[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] Installation of R-3.0.2 failed Fortran error

2014-01-24 Thread Sandip Nandi
Hi ,

 Fortran 4.3 which comes with SDK for suse 11 needs to compiled with a -0
instead of the default -O2 option . Can you try that.

Thanks
Sandip



On Fri, Jan 24, 2014 at 12:24 AM, Prof Brian Ripley
rip...@stats.ox.ac.ukwrote:

 On 24/01/2014 07:21, claus.neuma...@merckgroup.com wrote:

 Dear all,

 I have a big problem to compile  R-3.0.2 on our SUSE SLES 11 Server.
 Make breaks up with fortran errors and so the installation isn't
 successful
 This is a part from the make run output.:

 gcc-3.3 -fpic  -L/usr/lib64/gcc-lib/x86_64-suse-linux/3.3.3-hammer/ -lg2c
 -ffloat-store -c dlamch.f -o dlamch.o
 dlamch.f: In function `dlamch':
 dlamch.f:89: warning:
   INTRINSIC  DIGITS, EPSILON, HUGE, MAXEXPONENT,
 Reference to unimplemented intrinsic `DIGITS' at (^) (assumed EXTERNAL)
 dlamch.f:89:
   INTRINSIC  DIGITS, EPSILON, HUGE, MAXEXPONENT,
  ^
 Invalid declaration of or reference to symbol `digits' at (^) [initially
 seen at (^)]
 dlamch.f:89: warning:
   INTRINSIC  DIGITS, EPSILON, HUGE, MAXEXPONENT,
  ^
 Reference to unimplemented intrinsic `EPSILON' at (^) (assumed EXTERNAL)
 dlamch.f:89:
   INTRINSIC  DIGITS, EPSILON, HUGE, MAXEXPONENT,


 For me it is not clear that I have to set some flags, or install a other
 fortran compiler tha our gcc-3.3


 It will be clear if you read the 'R Installation and Administration
 Manual', as has already been pointed out to you.  If you need help with
 that, ask your IT support.

 Alternative, install a version of R of the same vintage as your compiler
 (not later than 2005, and not even the end of the GCC 3.x series).


  I would be very grateful for any help.
 Thanks a lot.


 Best regards

 Claus Neumayer

 IS-PDR-A Research
 D41/221
 HPC: D041/001
 Phone: +49(0)6151 724526
 Mobil: +49 15114544526
 Fax: +49(0)6151 914526
 Email: claus.neuma...@merck.de

 Merck KGaA
 Frankfurter Str. 250
 D 64293 Darmstadt
 Home:   www.merck.de



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


[[alternative HTML version deleted]]

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


[Rd] Using unicode from C interface of R

2014-01-21 Thread Sandip Nandi
Hi ,

I am using C interface of R . If a unicode string is read , in what format
I could pass it back to R ?
I was trying to use the following

 tpStr = ( char *)val;
 SET_STRING_ELT(innerList  , 0, mkChar(tpStr));

It does not work .

If I pass it back from as RAW format to R , what package is there to read
it ? I mean package for interpreting RAW data .

Thanks,
Sandip

[[alternative HTML version deleted]]

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


Re: [Rd] How to debug an R package (with C code)

2014-01-17 Thread Sandip Nandi
Hi ,

The video may help you

http://vimeo.com/11937905

Thanks,
Sandip


On Thu, Jan 16, 2014 at 4:17 PM, Ma, Saisai - maysy020 
saisai...@mymail.unisa.edu.au wrote:

 Hi all,

 Sorry to bother you.

 I am a beginner in R programming. I have encountered some problems when I
 modified a R package with C code.
 I would like to modified the C code within the R package, and want to
 debug the C program. But I have no idea how to debug this kind of R package.

 In the package, a R file named aaa.R use the interface .call(bbb.c, ...)
 to call the C code named bbb.c.
 And what I did is that I resourced aaa.R and ran it in R Stdio again,
 after modifying bbb.c. But there is nothing happened.
 I am very sure that the all the path of R file and C file is correct. And
 I am using Windows operating system.

 Could anyone give me a few pointers on how to debug R packages (or
 extensions with C++/C code)? If possible, Could you please give me an
 simple example or some command lines?


 Regards,
 Saisai


 [[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] Fwd: How to check if R interpreter is initiated

2013-12-20 Thread Sandip Nandi
Hi R-Developers ,

I am using R-3.1 , moved from R-2.15 . I am facing a problem which I have
raised in R bug report with bug 15596 .

My problem is how to check if R is initiated before initiating R

I am embedding R in parallel environment and reusing process already
running to reduce overhead . Each process is running infinitely. So when a
process is reused,it finds R is already initialized there and throws the
error.

Till 2.15 it was solved using R_Is_running variable . So I am assuming
there should be some flag or return value in R-3.0.2 which provides the
user with information if already initialized .

Anyone has faced the problem ?

It will be great if anyone could suggest alternate solution to this problem
for R-3.0.

Thanks,
Sandy

[[alternative HTML version deleted]]

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