hmnoidk
hmnoidk

Reputation: 565

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)

Upvotes: 1

Views: 797

Answers (1)

Ulises Rosas-Puchuri
Ulises Rosas-Puchuri

Reputation: 1970

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

Upvotes: 1

Related Questions