Check if character value is a valid R object name

后端 未结 2 1214
走了就别回头了
走了就别回头了 2020-12-17 04:50

Several months ago I asked something similar, but I was using JavaScript to check if provided string is a \"valid\" R object name. Now I\'d like to achieve the same by using

2条回答
  •  眼角桃花
    2020-12-17 05:31

    As Josh suggests, make.names is probably the best solution to this. Not only will it handle weird punctuation, it'll also flag reserved words:

    make.names(".x")   # ".x"
    make.names("_x")   # "X_x"
    make.names("if")   # " if."
    make.names("function")  # "function."
    

提交回复
热议问题