0

I already have this jpeg files of R plots and I want to chance the title name. The problem is that I need to upload this images and then change that (I just have the images. I don't have the code to make it again).

I would like to know if theres some way to chance this.

Thank you

  • 2
    Pretty unclear what you're asking without any [example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). If all you've got is images you need to add titles to, not anything R-dependent, you might just be better off doing that in image editing software. But again, that's just a guess – camille Feb 28 '20 at 16:25

1 Answers1

0

file.rename(from, to) will help.

wd="C:/Users/Public/r_img"

old_files=list.files(wd, full.names = TRUE)
no_of_files = length(old_files)
new_files=paste0(wd, '/' , 'NewFile' , c(1:no_of_files) , '.jpg')
file.rename(from = old_files, to = new_files)

print(old_files)
new_files=list.files(wd, full.names = TRUE)
print(new_files)

--print(old_files)

[1] "C:/Users/Public/r_img/OldFile1.jpg" "C:/Users/Public/r_img/OldFile10.jpg"

[3] "C:/Users/Public/r_img/OldFile2.jpg" "C:/Users/Public/r_img/OldFile3.jpg"

[5] "C:/Users/Public/r_img/OldFile4.jpg" "C:/Users/Public/r_img/OldFile5.jpg"

[7] "C:/Users/Public/r_img/OldFile6.jpg" "C:/Users/Public/r_img/OldFile7.jpg"

[9] "C:/Users/Public/r_img/OldFile8.jpg" "C:/Users/Public/r_img/OldFile9.jpg"

--print(new_files)

[1] "C:/Users/Public/r_img/NewFile1.jpg" "C:/Users/Public/r_img/NewFile10.jpg"

[3] "C:/Users/Public/r_img/NewFile2.jpg" "C:/Users/Public/r_img/NewFile3.jpg"

[5] "C:/Users/Public/r_img/NewFile4.jpg" "C:/Users/Public/r_img/NewFile5.jpg"

[7] "C:/Users/Public/r_img/NewFile6.jpg" "C:/Users/Public/r_img/NewFile7.jpg"

[9] "C:/Users/Public/r_img/NewFile8.jpg" "C:/Users/Public/r_img/NewFile9.jpg"

Kohelet
  • 394
  • 1
  • 6