从 R 运行 powershell 命令:表达式或语句中出现意外标记

2024-05-01

我尝试了以下命令(在 powershell 窗口中有效)

system('powershell -command \"Get-ChildItem -Filter "*.html" | Where-Object { $_.LastWriteTime -ge "11/12/2021 09:10:00" }\"')

但是,从 R 控制台我收到错误:

At line:1 char:79
+ ... er *.html | Where-Object { $_.LastWriteTime -ge 11/12/2021 09:10:00 }
+                                                                ~~~~~~~~
Unexpected token '09:10:00' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken
 
[1] 1

EDIT
使用 Mikael Jagan 的想法我得到了一个结果:

system(paste('powershell -command ',shQuote('Get-ChildItem -Filter "*.html" | Where-Object { $_.LastWriteTime -ge "11/30/2021 09:10:00" }')))

但是,如下所示,结果是字符向量而不是数据帧。有没有办法只获取带有文件名的矢量?

 [1] ""
 [2] ""
 [3] "    Directory: C:\\Users\\user\\Documents\\R_Data\\texk"
 [4] ""
 [5] ""
 [6] "Mode                 LastWriteTime         Length Name                                                                 "
 [7] "----                 -------------         ------ ----                                                                 "
 [8] "-a----        30/11/2021     10:31         386751 auth_cash_flow.html                                                  "
 [9] "-a----        30/11/2021     10:31         189370 auth_cash_flow_total.html                                            "
[10] "-a----        30/11/2021     10:31         552947 auth_symv_gantt.html                                                 "
[11] "-a----        30/11/2021     10:31          93238 auth_tender_schedule.html                                            "
[12] "-a----        30/11/2021     10:30         683088 dev_constr_pivot.html                                                "
[13] "-a----        30/11/2021     10:30          70224 form_org_chart.html                                                  "
[14] "-a----        30/11/2021     10:31         199907 form_org_chart2.html                                                 "
[15] "-a----        30/11/2021     10:30         618821 form_workload.html                                                   "
[16] "-a----        30/11/2021     10:30         109127 index.html                                                           "
[17] ""
[18] ""

这是我的会话信息:

> sessionInfo()
R version 4.0.5 (2021-03-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=Greek_Greece.1253  LC_CTYPE=Greek_Greece.1253    LC_MONETARY=Greek_Greece.1253
[4] LC_NUMERIC=C                  LC_TIME=Greek_Greece.1253    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.0.5 tools_4.0.5 

x <- system(paste('powershell -command ',shQuote('Get-ChildItem -Filter "*.html" | Where-Object { $_.LastWriteTime -ge "11/30/2021 09:10:00" } | Select -exp Name')), intern = TRUE)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 R 运行 powershell 命令:表达式或语句中出现意外标记 的相关文章

随机推荐