FW: [R] the underscore ("_") in variable name
Jacob Anhoj
anhoej at dadlnet.dk
Mon Oct 2 11:15:09 CEST 2000
don't know much about programming. But I know that it is not a good idea to
assign a variable name to the name of an intrinsic constant or function. In
your example, you assign the name "c" to a variable. But "c" is already the
name of a function i R. In this way you are asking for trouble.
-----Original Message-----
From: owner-r-help at stat.math.ethz.ch
[mailto:owner-r-help at stat.math.ethz.ch]On Behalf Of mohd zamri
Sent: 2. oktober 2000 08:36
To: r-help at stat.math.ethz.ch
Subject: [R] the underscore ("_") in variable name
new to R and starting to learn to program R. The underscore ("_") did some
suprising result. e.g
> c <- c(1,2,3,4,5)
> mean(c)
[1] 3
> c_mean <- mean(c)
> c
[1] 3
having some experience in C, I thought the underscore is "always" valid in
variable name. totally confuse me. Reread the R-FAQ a few times, and found
on pg. 7 foot-note which states that;
the underscore character "_" is an alllowable synonym for the left
pointing assignment operator "<-", ...........
it is appear that R parse "c_mean <- mean(c)" as "c <- mean <- mean(c)",
which explain the result.
suggestion:
I believe it would be helpful if this point be make clear on the FAQ, and
not mention as a footnote. What is a proper naming convention and a few
example of valid/invalid name for variables.
zamri
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list