Yolo_chicken
Yolo_chicken

Reputation: 1381

R use input filename as output filename

I would like to have a R filename have the same input name but with a few characters attached to the end, such as

input = data

output= data_addition

Here is what I have so far:

input= file.path("E:/dir/folder/inputName.csv")
name = basename(input)
data = read.csv(file,skip=10)

And I'm not sure what to write in the write.csv(data,????). I've done similiar operations with Python but not in R.

Upvotes: 1

Views: 678

Answers (1)

loki
loki

Reputation: 10340

You can use substr like this:

outname <- paste0(substr(input, start = 1, stop = nchar(input) - 4), "your_addition.csv")
write.csv(data, outname)

Upvotes: 1

Related Questions