On Fri, Dec 07, 2001 at 09:53:28PM -0800, Jeff D. Hamann wrote:> I see the uderscore "_" is not allowed in R. This make R a real drag when > trying to use with SQL packages and c code.A work-around I use is make.names(), which converts "illegal" variable names to legal ones in R. names(some.data.object)<-make.names(names(some.data.object)) if you've somehow managed to get an illegal name in there. e.g.> zz<-data.frame(c(1,2,3),c(4,5,6)) > zzc.1..2..3. c.4..5..6. 1 1 4 2 2 5 3 3 6> names(zz)<-c("age","number_of_feet") > > zzage number_of_feet 1 1 4 2 2 5 3 3 6> names(zz)<-make.names(names(zz)) > zzage number.of.feet 1 1 4 2 2 5 3 3 6>Cheers Jason -- Indigo Industrial Controls Ltd. 64-21-343-545 jasont at indigoindustrial.co.nz -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I see the uderscore "_" is not allowed in R. This make R a real drag when trying to use with SQL packages and c code. Why is the underscore not allowed and will it be allowed in a future release? Jeff. Jeff D. Hamann Hamann, Donald and Associates PO Box 1421 Corvallis, Oregon USA 97339-1421 Bus. 541-753-7333 Cell. 541-740-5988 jeff_hamann at hamanndonald.com www.hamanndonald.com -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Jeff D. Hamann writes:> I see the uderscore "_" is not allowed in R. This make R a real drag when > trying to use with SQL packages and c code. Why is the underscore not > allowed and will it be allowed in a future release?But the underscore ***is*** allowed in R!!! E.g.> x _ 42 > x[1] 42 :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) cheers, Rolf Turner -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Presumably you want to use the underscore in variable names. But, as you've seen, it has another meaning, which is <-. What you _can_ use is a period (".") or, since R is case sensitive, you can do things like VarName1, VarName2, VarName1Length. Jon Baron -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dear Jeff, At 09:53 PM 12/7/2001 -0800, Jeff D. Hamann wrote:>I see the uderscore "_" is not allowed in R. This make R a real drag when >trying to use with SQL packages and c code. Why is the underscore not >allowed and will it be allowed in a future release?As has been pointed out, the underscore is used as a synonym for the assignment operator, <-, but non-standard names, including names containing underscores, can be used -- if this is really necessary -- by quoting them. For example: > "x_1" <- 1:5 > eval(as.name("x_1")) [1] 1 2 3 4 5 If you're receiving the offending variable names from another application, an alternative is to edit the names, as in > gsub("_", ".", c("x_1", "x_2")) [1] "x.1" "x.2" > I hope that this helps, John ----------------------------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario, Canada L8S 4M4 email: jfox at mcmaster.ca phone: 905-525-9140x23604 web: www.socsci.mcmaster.ca/jfox ----------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Jeff D. Hamann <jeff_hamann at hamanndonald.com> writes:>I see the uderscore "_" is not allowed in R. This make R a real drag when >trying to use with SQL packages and c code. Why is the underscore not >allowed and will it be allowed in a future release?Underscore is allowed but is a 'special' character meaning assign to the LHS (i.e. it is equivalent to <-). I believe that it is not common or recommended usage but remains in R for backward compatibility and for compatibility with S/S+. I assume that you want to sue it a a separator in variable names (e.g. my_variable. R convention is to use the period (e.g. my.variable) but this may be a little confusing as the period tends to be used as a a delimiter between table and variable names rather like $ in R. You can use the underscore in variable names if you quote the name (e.g. "my_variable") wherever you use it. This might prove tediously prone to error. My suggestion is to convert all variable names to standard R names (i.e. by replacing _ with .) before soing anything with the data ... see help(make.names) for details on how to do this simply. Mark -- Mark Myatt -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._