Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 逻辑测试对象是否为目录_R - Fatal编程技术网

R 逻辑测试对象是否为目录

R 逻辑测试对象是否为目录,r,R,假设我刚刚创建了这个目录和文件: dir.create("foo") cat("bar", file="bar") #both files exist: file.exists("foo") file.exists("bar") 我想测试foo和bar,以便在逻辑上测试它们是否为目录。如果某物是一个目录,我希望能够将其他文件放在其中。如果项目不是目录,我想使用stop,但不知道如何测试 四处闲逛让我: file.info("foo", "bar") .Internal(file.info(

假设我刚刚创建了这个目录和文件:

dir.create("foo")
cat("bar", file="bar")

#both files exist:

file.exists("foo")
file.exists("bar")
我想测试foo和bar,以便在逻辑上测试它们是否为目录。如果某物是一个目录,我希望能够将其他文件放在其中。如果项目不是目录,我想使用
stop
,但不知道如何测试

四处闲逛让我:

file.info("foo", "bar")
.Internal(file.info(fn <- c("foo", "bar")))
file.info(“foo”、“bar”)

.Internal(file.info)(fn也许您想要
文件测试

file_test("-d", c("foo", "bar"))
# [1]  TRUE FALSE

file.info
显然依赖于平台,在Windows上使用
\u wstati64
,在Linux上使用
stat
。有关
file.info
的实际工作原理,请参见,这是由
.Internal(file.info)
调用的C函数,但我猜(?)这并不是你真正想要的……太好了。非常感谢你。@Tylerlinker——很高兴能帮上忙。我不是试图记住所有与R的
文件相关的函数,而是经常发现自己在做
方面的事(“^file”)
。它遗漏了一些,但给出了一个很好的开始列表;)