[Rd] reshape direction="long" does not drop temporary ID (PR#8152)

2005-09-23 Thread aniko . szabo
Full_Name: Aniko Szabo
Version: 2.1.0
OS: Windows XP
Submission from: (NULL) (155.100.234.96)


When using reshape with direction="long", multiple id variables and only one
column of varying data, the resulting data frame has a temporary ID variable.
Here is an example:

a <- data.frame(G=LETTERS[1:3], H=letters[1:3], x=1:3)
reshape(a, direction="long", varying=list(c("x")), idvar=c("G","H"))

  G H tempID29457 time x
1 A a A.a1 1
2 B b B.b1 2
3 C c C.c1 3

While I understand that there was not much point to reshaping, I think it is
still a bug.

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


[Rd] missing IntegerFromString()

2007-06-05 Thread Aniko Szabo
I have created a DLL not so long ago using C code. My code used the
IntegerFromString() function that used to be exported in the
Rinternals.h header file (and thus easily accessible). Recently I
upgraded to R 2.5.0 and my DLL stopped working. I see that the
IntegerFromString() function is not exported in any of the header files
in the RHOME\include directory. Is it possible for me to use it without
installing all R source files? I can see that the function is in
coerce.c, however it #includes other stuff that I don't have and I am
afraid to mess things about by doing things I don't understand. Or
perhaps there is another function that is intended to be used instead?

 

Thanks,

Aniko

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


Re: [Rd] missing IntegerFromString()

2007-06-07 Thread Aniko Szabo
Thanks to everybody who responded to my question.
asInteger(coerceVector(x,INTSXP)) indeed does what I need. I guess there
is a lot I don't understand about type coercion, as I would not have
expected it to work.

Aniko

-Original Message-
From: Seth Falcon [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, June 05, 2007 11:24 PM
To: Aniko Szabo
Cc: r-devel@r-project.org
Subject: Re: [Rd] missing IntegerFromString()

Hi Aniko,

"Aniko Szabo" <[EMAIL PROTECTED]> writes:

> I have created a DLL not so long ago using C code. My code used the
> IntegerFromString() function that used to be exported in the
> Rinternals.h header file (and thus easily accessible). Recently I
> upgraded to R 2.5.0 and my DLL stopped working. I see that the
> IntegerFromString() function is not exported in any of the header
files
> in the RHOME\include directory. Is it possible for me to use it
without
> installing all R source files? I can see that the function is in
> coerce.c, however it #includes other stuff that I don't have and I am
> afraid to mess things about by doing things I don't understand. Or
> perhaps there is another function that is intended to be used
> instead?

I think you want asInteger (which calls IntegerFromString).  This is
in RHOME/include/Rinternals.h

Best Wishes,

+ seth

PS: Nice to see you again :-)


-- 
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research
Center
http://bioconductor.org

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


Re: [Rd] missing IntegerFromString()

2007-06-07 Thread Aniko Szabo
I am sorry about the confusion, I was too hasty.
asInteger(coerceVector(x,INTSXP)) does not work after all. Here are more
details of what I am trying to accomplish: I have a matrix with column
names that are actually known to be integers (because I set them so
myself in the R code, say, colnames(mat) <- 1:10. Of course, they become
converted to character strings.)

The relevant part of my code used to be:

SEXP MyFunction(SEXP mat);
int warn, minY 
SEXP rl, cl;
char *rn, *cn;
GetMatrixDimnames(mat, &rl, &cl, &rn, &cn);
minY = IntegerFromString(VECTOR_ELT(cl,0), &warn);
if (warn > 0) error("Names of popmatrix columns are not
integers");

Running some tests it appears that VECTOR_ELT(cl,0) is CHARSXP (which I
wound up using without even knowing it).
I tried replacing the IntegerFromString part with both
asInteger(VECTOR_ELT(cl,0)) and with
asInteger(coerceVector(VECTOR_ELT(cl,0),INTSXP)), but as you surmised,
since VECTOR_ELT(cl,0) is CHARSXP, it does not work.

So, how could I get the actual values in the column names?

Thanks for all your help,
Aniko



-Original Message-
From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 07, 2007 12:51 PM
To: Simon Urbanek
Cc: Douglas Bates; Aniko Szabo
Subject: Re: [Rd] missing IntegerFromString()

On Thu, 7 Jun 2007, Simon Urbanek wrote:

>
> On Jun 7, 2007, at 1:00 PM, Prof Brian Ripley wrote:
>
>> On Thu, 7 Jun 2007, Simon Urbanek wrote:
>> 
>>> 
>>> On Jun 7, 2007, at 11:33 AM, Douglas Bates wrote:
>>> 
>>>> On 6/6/07, Aniko Szabo <[EMAIL PROTECTED]> wrote:
>>>>> Thanks to everybody who responded to my question.
>>>>> asInteger(coerceVector(x,INTSXP)) indeed does what I need. I guess
>>>>> there
>>>>> is a lot I don't understand about type coercion, as I would not
have
>>>>> expected it to work.
>>>> 
>>>> It is better to use
>>>> 
>>>> asInteger(x)
>>>> 
>>>> which will do the coercion if necessary.
>>> 
>>> Unfortunately not if it gets a character vector:
>> 
>> Yes, if it gets a character *vector*, no if it gets a CHARSXP.
>> 
>
> Indeed, I was starting with an assumption that the task at hand is to
get the 
> same result as as.integer in R code from a string - mea culpa. I had
the 
> impression that it was likely what Aniko wanted (because anything else
would 
> work with trivial asInteger which I assumed was not enough). Yes, I
made too 
> many unsafe assumptions ;).

You weren't the only one: I think we all are a little confused here 
The positive outcome is that I will make asInteger work on CHARSXPs as 
well.

Brian

>
> Sorry for the noise,
> Simon
>
>
>>>> .Call("foo","1")
>>> Error: unimplemented type 'character' in 'asInteger'
>>> 
>>> 
>>>> When you do the coercion
>>>> yourself you should PROTECT the result then UNPROTECT it.  Calling
>>>> asInteger directly avoids this overhead without the risk of losing
>>>> data in a garbage collection.  asInteger can accomplish this
because
>>>> only the first element of the SEXP x is converted to an integer.
>>>> 
>>> 
>>> It could, but doesn't ;). That is what the original
IntegerFromString
>>> did, but now you either have to do that yourself or coerce the whole
>>> vector (not as efficient but easier to write :P).
>> 
>> But does coerceVector really handle CHARSXPs?  There are not vectors
and I 
>> don't see it in the code. Consider
>> 
>> #include 
>> 
>> SEXP foo(SEXP x)
>> {
>>   return coerceVector(STRING_ELT(x, 0), INTSXP);
>> }
>> 
>> SEXP foo2(SEXP x)
>> {
>>   Rprintf("%d\n", asInteger(STRING_ELT(x, 0)));
>>   return x;
>> }
>> 
>>> .Call("foo","1")
>> Error: cannot coerce type char to integer vector
>>> .Call("foo2","1")
>> -2147483648
>> [1] "1"
>> 
>> (and that is NA_INTEGER).
>> 
>> As I said, if asInteger(coerceVector(x,INTSXP)) works, 'x' is not a 
>> CHARSXP.  So I have little idea what the actual story here is.
>> 
>> Brian
>> 
>> 
>>> Cheers,
>>> Simon
>>> 
>>> 
>>>>> 
>>>>> Aniko
>>>>> 
>>>>> -Original Message-
>>>>> From: Seth Falcon [mailto:[EMAIL PROTECTED]
>>>>> Sent: Tuesday, June 05, 2007 11:24 PM
>