r - 错误: 'dir' command not found while using System function in R

标签 r windows

我想在代码中使用R的System函数,因此我编写了简单的单行代码来检查其是否正常运行。这是我的一支类轮-

system("dir", intern = TRUE)

我正在使用Windows,因此它应该给我与命令提示符相同的输出(显示当前目录中存在的所有文件)。而是导致了错误:

Error in system("dir", intern = TRUE) : 'dir' not found

最佳答案

根据?system的描述:

command must be an executable (extensions ‘.exe’, ‘.com’) or a batch file (extensions ‘.cmd’ and ‘.bat’): these extensions are tried in turn if none is supplied. This means that redirection, pipes, DOS internal commands, ... cannot be used: see shell if you want to pass a shell command-line.



因此,不能使用DOS内部命令。它实际上不会为我返回任何错误,但它不会返回任何内容。

但是,shell可以按预期工作:
 shell('dir', intern = TRUE)
 #[1] " Volume in drive C is "                                                  
 #[2] " Volume Serial Number is "                                            
 #[3] ""                                                                              
 #[4] " Directory of C:\\Users\\TB\\Documents"                             
 #[5] ""                                                                              
 #[6] "07/06/2019  11:10    <DIR>          ."     
 #.....                                    

关于r - 错误: 'dir' command not found while using System function in R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56629886/

相关文章:

r - 使用 rvest,是否可以单击激活 div 并显示新内容以进行抓取的选项卡

r - 当时区不同时检查日期是否相等

r-在向量中找到两个最接近的值

PHP 如何启动 Windows GUI 应用程序

r - 在 R 中,如何根据包含我想要匹配的值的相邻列中的间隔查找一列中的值?

vb.net - 仅编译 ffmpeg 解码而不使用音频编解码器

python - 在 Visual Studio Code 中运行外部程序时出现 "Unable to find thread for evaluation."

windows - 批处理文件:从串行端口接收数据并将其写入 txt 文件

c++ - 我可以使用 Visual Studio 以外的 IDE 来开发 Windows GPIO 驱动程序吗?

R - 提取具有模式的单词并用相反顺序的单词替换它们