Invalid from argument in file.rename


#1

Could you please help me to find out what is wrong with this script? I get the output below. it seems to me that the 2 lists have the same length, so I do not see where the issue is.

Thanks,

> 
> new_dataFns <- list("name1", "name2", "name3")
> new_path <-  lapply(new_dataFns,
+                      function(new_dataFns){
+                        paste(getwd(), "/OUT/openMS/INPUT_DATA/INPUT_DATA_OUT/", new_dataFns, sep = "")
+                      })
> 
> print(new_path)
[[1]]
[1] "/home/giuseppa/Development/glycoPipeApp/OUT/openMS/INPUT_DATA/INPUT_DATA_OUT/name1"

[[2]]
[1] "/home/giuseppa/Development/glycoPipeApp/OUT/openMS/INPUT_DATA/INPUT_DATA_OUT/name2"

[[3]]
[1] "/home/giuseppa/Development/glycoPipeApp/OUT/openMS/INPUT_DATA/INPUT_DATA_OUT/name3"
> 
> old_dataFns <- list("1.csv", "2.csv", "3.csv")
> 
> for(i in 1:length(old_dataFns)){
+   old_dataFns[i] <- gsub(" ", "", paste(getwd(), "/","OUT/openMS/INPUT_DATA/INPUT_DATA_OUT/", old_dataFns[i]))
+ 
+ }
> print(old_dataFns)
[[1]]
[1] "/home/giuseppa/Development/glycoPipeApp/OUT/openMS/INPUT_DATA/INPUT_DATA_OUT/1.csv"

[[2]]
[1] "/home/giuseppa/Development/glycoPipeApp/OUT/openMS/INPUT_DATA/INPUT_DATA_OUT/2.csv"

[[3]]
[1] "/home/giuseppa/Development/glycoPipeApp/OUT/openMS/INPUT_DATA/INPUT_DATA_OUT/3.csv"

> 
> 
> file.rename(from = old_dataFns, to = new_dataFns)
new_dataFns <- list("name1", "name2", "name3")
new_path <-  lapply(new_dataFns,
                     function(new_dataFns){
                       paste(getwd(), "/OUT/openMS/INPUT_DATA/INPUT_DATA_OUT/", new_dataFns, sep = "")
                     })

print(new_path)
#> [[1]]
#> [1] "/tmp/Rtmp45cbvl/reprex2bdc450de1a6/OUT/openMS/INPUT_DATA/INPUT_DATA_OUT/name1"
#> 
#> [[2]]
#> [1] "/tmp/Rtmp45cbvl/reprex2bdc450de1a6/OUT/openMS/INPUT_DATA/INPUT_DATA_OUT/name2"
#> 
#> [[3]]
#> [1] "/tmp/Rtmp45cbvl/reprex2bdc450de1a6/OUT/openMS/INPUT_DATA/INPUT_DATA_OUT/name3"

old_dataFns <- list("1.csv", "2.csv", "3.csv")

for(i in 1:length(old_dataFns)){
  old_dataFns[i] <- gsub(" ", "", paste(getwd(), "/","OUT/openMS/INPUT_DATA/INPUT_DATA_OUT/", old_dataFns[i]))

}
print(old_dataFns)
#> [[1]]
#> [1] "/tmp/Rtmp45cbvl/reprex2bdc450de1a6/OUT/openMS/INPUT_DATA/INPUT_DATA_OUT/1.csv"
#> 
#> [[2]]
#> [1] "/tmp/Rtmp45cbvl/reprex2bdc450de1a6/OUT/openMS/INPUT_DATA/INPUT_DATA_OUT/2.csv"
#> 
#> [[3]]
#> [1] "/tmp/Rtmp45cbvl/reprex2bdc450de1a6/OUT/openMS/INPUT_DATA/INPUT_DATA_OUT/3.csv"


file.rename(from = old_dataFns, to = new_dataFns)
#> Error in file.rename(from = old_dataFns, to = new_dataFns): invalid 'from' argument

Created on 2018-09-19 by the reprex package (v0.2.1)