<p style="">Hey.</div><p style=""><br></div><p style="">I am wondering if there's some general guidance on what the 'right' options are to cleanly handle character arguments passed from R to Rcpp.</div><p style=""><br></div><p style="">It is all rather simple: let's say I have a human-readable argument vector c("tree", "herb", "shrub") [It could also be a factor in R], which I can send to an Rcpp function along with other arguments for evaluation.</div><p style="">What would be the cleanest way to define those arguments (plant types) in R to then have as little trouble sending them over to Rcpp for use in cases like if() statements?</div><p style=""><br></div><p style=""><br></div><p style="">The use of enums comes to mind:</div><p style=""><br></div><p style="">// beginningoffile</div><p style="">enum class var_type { flower, tree };</div><p style=""><br></div><p style="">RCPP_EXPOSED_ENUM_NODECL(var_type)</div><p style=""><br></div><p style="">// [[Rcpp::export]]</div><p style="">int charHandle1(var_type text_arg = var_type::flower) {</div><p style=""> if(text_arg == var_type::flower) {</div><p style="">   Rcout << static_cast<int>(text_arg) << " says '0 (flower)'.\n";</div><p style=""> } else if(text_arg == var_type::tree) {</div><p style="">   Rcout << static_cast<int>(text_arg) << " says '1 (tree)'.\n";</div><p style=""> }</div><p style=""> return 0;</div><p style="">}</div><p style="">// endoffile</div><p style=""><br></div><p style="">This however, doesn't seem to work. I understand R would have to know the var_type for it to work. </div><p style="">Then I can do it simply by comparing the const char * argument. This will work, but the strcmp() comparison isn't very straightforward for someone who doesn't know C++ (and perhaps for some other reasons).</div><p style=""><br></div><p style="">// [[Rcpp::export]]</div><p style="">int charHandle2(const char* text_arg = "flower") {</div><p style=""> if(strcmp(text_arg, "flower") == 0) {</div><p style="">   Rcout << text_arg << " says 'flower'.\n";</div><p style=""> } else if(strcmp(text_arg, "tree") == 0) {</div><p style="">   Rcout << text_arg << " says 'tree'.\n";</div><p style=""> }</div><p style=""> return 0;</div><p style="">}</div><p style=""><br></div><p style="">I am looking for some good practice guidance on how to handle this safely and legibly to avoid sending people to function definitions. An argument could be made, for instance, that a list of plant type arguments could be stored as factor in R and then sent and used in some way in Rcpp. What other options are there? To my best knowledge, support for enums is limited - I glanced over the vignettes and couldn't find any significant mention of enums (or factors, really), so I guess some other way of handling such cases should be taken. Has anyone dealt with such cases and has recommendations?</div><p style=""><br></div><p style="">Regards,</div><p style="">Angelo (Greetings from Genoa)</div>