jeromyanglim / learning_r

assorted notes to self while learning R
1 stars 0 forks source link

How to convert string into legitimate file name in R? #6

Closed jeromyanglim closed 12 years ago

jeromyanglim commented 12 years ago

I have a database with participant names and I want to use the participant name to generate file names. However, there are few names like "A/Prof" where illegal characters for file names appear. How can I cleanse these raw names.

jeromyanglim commented 12 years ago

One simple strategy:

gsub('[^a-zA-Z]', '', x)

This will remove any characters in x that are not lower or upper case letters between a and Z.

Limitations: a broader range of characters are permitted in file names, and this does not deal with long strings.