Skip to content
Related Articles
Open in App
Not now

Related Articles

Rename Files Using R

Improve Article
Save Article
  • Difficulty Level : Hard
  • Last Updated : 14 Sep, 2021
Improve Article
Save Article

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)


  • to: character vector that contains all the files to be renamed
  • from: character vector that contains new names for file

File for demonstration:


Below is the implementation:

Here we first list out the working directory and then use rename() function to rename the file name.


# Define working directory
working_directory <- "working/dic/"
# get list of current file
# names as character vector current_files
current_files <- list.files(working_directory)
# get file names after renaming
# as character vector new_files
new_files <- c("geeks1.txt","geeks2.txt")
# Use file.rename() function to rename files
file.rename(paste0(working_directory, current_files),
            paste0(working_directory, new_files))



Final Directory

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!