1

I have datafile named dat1 I want to rename it to dat2 which I have stored in the object filename.

dat1 <- c(1:5) filename <- paste("dat2") 

If I use,

filename <- dat1 

Then the dat1 is renamed to filename and not to dat2.

So how do I rename dat1 with the name stored in the object filename i.e. without mentioning dat2?

I tried using file.rename and mv but unsuccessful.

1 Answer 1

1

We can use assign

assign(filename, dat1) dat2 #[1] 1 2 3 4 5 

and now rm the dat1

rm(dat1) 

Or another option is mv from gdata

library(gdata) mv(from = 'dat1', to = filename) dat2 #[1] 1 2 3 4 5 dat1 

Error: object 'dat1' not found


file.rename is used to rename a file name and not the objects in the global environment

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.