[Solved] How to extract list element names in lapply to rename files

[ad_1]

We need to use names instead of name in the OP’s function, use paste0 instead of paste if we don’t need a whitespace between the names and the new string, and return ‘theNamedFile’, then apply the function directly on the ‘mylist’

ReportOp<-function(x){
    theNamedFile <- paste0(names(x),"~\\Myfile.pdf")
    theNamedFile
 }
ReportOp(mylist)

If we apply it using lapply

lapply(mylist, ReportOp)

this will return the names of the elements (if is a named vector or the column names of data.frame) as a list

4

[ad_2]

solved How to extract list element names in lapply to rename files