Variable name restrictions in R

前端 未结 4 1234
慢半拍i
慢半拍i 2020-11-29 06:01

What are the restrictions as to what characters (and maybe other restrictions) can be used for a variable name in R?

(This screams of general reference, but I can\'t

4条回答
  •  北海茫月
    2020-11-29 07:00

    Using the make.names() function from the built in base package may help:

    is_valid_name<- function(x)
    {
      length_condition = if(getRversion() < "2.13.0") 256L else 10000L
      is_short_enough = nchar(x) <= length_condition
      is_valid_name = (make.names(x) == x)
    
      final_condition = is_short_enough && is_valid_name
      return(final_condition)
    }
    

提交回复
热议问题