我使用RSelenium
下载多个(125)电子表格,其中包含从网页到目录所需的数据。网站生成的文件总是以" report"命名,因此下载的文件名为" report(1)"到"报告(124)"。
我有一个字符向量,其中包含我希望使用' file.rename'重命名文件的文件的名称。但是,虽然文件按照文件夹中下载的顺序显示(我使用的是Windows 10 FYI),但当我使用list.files
时,它按以下顺序提供给我(结果缩写为前25;我手动将第一个文件重命名为" areport.xls"将其放在第一位。
[1] "areport.xls" "report (1).xls" "report (10).xls" "report (11).xls" "report (12).xls" "report (13).xls" "report (14).xls"
[8] "report (15).xls" "report (16).xls" "report (17).xls" "report (18).xls" "report (19).xls" "report (2).xls" "report (20).xls"
[15] "report (21).xls" "report (22).xls" "report (23).xls" "report (24).xls" "report (3).xls" "report (4).xls" "report (5).xls"
[22] "report (6).xls" "report (7).xls" "report (8).xls" "report (9).xls"
订单似乎没有押韵或理由(我想因为文件名是以字符串形式读取的?)。我需要一种方法以正确的顺序读取文件名,以便为它们提供正确的新名称。
有什么建议吗?
答案 0 :(得分:1)
知道gtools库中有一个函数真的是唯一需要的解释:
> library(gtools)
> x <- scan(what="")
1: "areport.xls" "report (1).xls" "report (10).xls" "report (11).xls" "report (12).xls" "report (13).xls" "report (14).xls"
8: "report (15).xls" "report (16).xls" "report (17).xls" "report (18).xls" "report (19).xls" "report (2).xls" "report (20).xls"
15: "report (21).xls" "report (22).xls" "report (23).xls" "report (24).xls" "report (3).xls" "report (4).xls" "report (5).xls"
22: "report (6).xls" "report (7).xls" "report (8).xls" "report (9).xls"
26:
Read 25 items
> ?mixedsort
> mixedsort(x)
[1] "areport.xls" "report (1).xls" "report (2).xls" "report (3).xls" "report (4).xls" "report (5).xls" "report (6).xls"
[8] "report (7).xls" "report (8).xls" "report (9).xls" "report (10).xls" "report (11).xls" "report (12).xls" "report (13).xls"
[15] "report (14).xls" "report (15).xls" "report (16).xls" "report (17).xls" "report (18).xls" "report (19).xls" "report (20).xls"
[22] "report (21).xls" "report (22).xls" "report (23).xls" "report (24).xls"