[Rd] string comparison

From: Kjell Konis <kjell.konis_at_epfl.ch>
Date: Thu, 07 Aug 2008 16:03:15 +0200


Hi,

I have a package where I do things like this a lot:

   if(strncmp(CHAR(asChar(Scategory)), "chance", 6) == 0)      category = h_category_chance;
   else if(strncmp(CHAR(asChar(Scategory)), "utility", 7) == 0)      category = h_category_utility;
   else if(strncmp(CHAR(asChar(Scategory)), "decision", 8) == 0)      category = h_category_decision;
   else if(strncmp(CHAR(asChar(Scategory)), "instance", 8) == 0)      category = h_category_instance;
   else
     category = h_category_error;

I would like to replace the strncmps with pointer comparisons so I set up some global variables in the R_init_myDLL function like this:

   charChance = install("chance")
   <etc.>

but I can't seem to get the comparison to work. I want to do something like

   if(CHAR(asChar(Scategory)) == charChance)      category = h_category_chance;

but category always ends up being h_category_error. Any pointers would be appreciated.

Thanks,
Kjell



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 07 Aug 2008 - 14:53:23 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 Thu 07 Aug 2008 - 16:36:18 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.

list of date sections of archive