In this article, we are going to see how to rename files using R Programming Language.
To rename a file in R we use file.rename(). This function renames all the files mentioned as parameters. It returns normally TRUE for success, FALSE for failure.
Note: File naming conventions depend on the platform.
Syntax: file.rename( to, from)
Parameters:
- to: character vector that contains all the files to be renamed
- from: character vector that contains new names for file
File for demonstration:
Directory
Below is the implementation:
Here we first list out the working directory and then use rename() function to rename the file name.
R
working_directory <- "working/dic/"
current_files <- list.files (working_directory)
new_files <- c ( "geeks1.txt" , "geeks2.txt" )
file.rename ( paste0 (working_directory, current_files),
paste0 (working_directory, new_files))
|
Output:
TRUE TRUE
Final Directory
Last Updated :
14 Sep, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...