Re: [Rd] missing IntegerFromString()

From: Seth Falcon <sfalcon_at_fhcrc.org>
Date: Thu, 07 Jun 2007 23:41:26 -0700

"Aniko Szabo" <aszabo_at_hpi.mcw.edu> writes:

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

How about:

  SEXP colnums;
  int *ivals;
  PROTECT(colnums = coerceVector(cl, INTSXP));   ivals = INTEGER(colnums);

Here you convert the STRSXP cl into an INTSXP. If you want the actual integer values, use the ivals pointer.

+ seth

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

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Fri 08 Jun 2007 - 06:45:16 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 08 Jun 2007 - 07:34:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.