Search code examples
rvariablesreadlines

How to read in a file and have its variable name automatically take on the file name?


How can I use something like readLines to save the file as a character string in my environment with its own file name as the variable?

I tried something like the pseudocode below without success.

paste(filename) <- readLines(filename)

Solution

  • assign function could be an alternative:

    assign("filename", readLines("filename"))
    

    if your filename starts with a character different from a to z (e.g. ., _), you can always call your variable circumscribed with `` symbols