Smart Guy
2011-Oct-04 04:19 UTC
[R] The use of period in function names and variable names
Hi, I am looking for some guidance on whether I can use the period(.) in function names and variable names. For example: my.function.name <- function(my.data.variable, my.radius, my.another.var, my.value = 10) { } Will this pose any problems regarding older and current version of R. -- SmartG [[alternative HTML version deleted]]
Steve Lianoglou
2011-Oct-04 04:30 UTC
[R] The use of period in function names and variable names
Hi, On Tue, Oct 4, 2011 at 12:19 AM, Smart Guy <smartguy3k at gmail.com> wrote:> Hi, > ? ? I am looking for some guidance on whether I can use the period(.) in > function names and variable names.Yes you can.> For example: > > my.function.name <- function(my.data.variable, my.radius, my.another.var, > my.value = 10) > { > > } > > Will this pose any problems regarding older and current version of R.Not really. For the most part, you can use this pattern as you like. One thing to keep in mind is that S3 method dispatch matches methods based on a METHOD_NAME.OBJECT_CLASS pattern. If you want to know more about the S3 stuff, you can start at ?UseMethod. -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology ?| Memorial Sloan-Kettering Cancer Center ?| Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact
S Ellison
2011-Oct-04 11:04 UTC
[R] The use of period in function names and variable names
See para 10.3.2 'Identifiers' in the R language definition (always distributed with R in the html help system), or ?make.names, for a concise statement of what constitutes a valid variable name in R. It's actually underscores that might give trouble with older versions, not '.'. But they'd have to be a lot older by R standards (pre 1.9.0). I am not sure why there has been a recent shift away from periods and towards camelCase in some R packages; personally I find a period or underscore much more useful for making a variable name readable. And a mix of camelCase and period.breaks makes it a lot harder to guess which case-sensitive string to use. The number of different combinations of case and period I end up trying for R.Version (occasionally used, never quite often enought to be automatic) defies belief ;-). S Ellison> From: r-help-bounces at r-project.org On Behalf Of Smart Guy > Sent: 04 October 2011 05:20 > To: r-help at r-project.org > Subject: [R] The use of period in function names and variable names > > Hi, > I am looking for some guidance on whether I can use the > period(.) in function names and variable names.******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}
Hello. Not at all in the way you have shown. Just to improve your code "readability", try to avoid naming your variables beginning with period (example: .hello). In contrast with Matlab (for example) the period in R is not to have access to an object property. -- View this message in context: http://r.789695.n4.nabble.com/The-use-of-period-in-function-names-and-variable-names-tp3869913p3871407.html Sent from the R help mailing list archive at Nabble.com.