This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Saving A Table In R With Its Own Name

Hi,

I would like to know, whether it is possible to read one table into R and use the name of the file also as an object name

This should look some thing like that:

tablename.txt <- read.delim2("tablename.txt", sep="\t")

But I would like to able to assign tablename.txt automatically, without me having to change it each time.

is it possible to do it with assign?

Thanks

Assa

r

1 answer

Ok

I solved the problem.

It was possible by saving the list of files into R as list and than assign them each time to the read.table command as this:

list_names = as.list(dir(pattern="*.txt"))
assign(list_names[[1]], read.delim2("tablename.txt", sep="\t", skip=1))

In case your first file in list_name is not tablename.txt

list_names = as.list(dir(pattern="*.txt"))
assign(list_names[[1]], read.delim2(list_names[[1]], sep="\t", skip=1))

You're right. it was a typing error. I meant that. thanks

Log in to answer this question.