Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.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,在RUnit测试中,我有以下代码片段: checkTrue(!file.exists(fname)) doSomething() #cat(fname);print(file.info(fname)) checkTrue(file.exists(fname)) 第二次调用checkTrue()失败,即使doSomething()创建了一个文件。我已经确认文件在那里,上面显示了注释掉的行 因此,我想知道对file.exists的第二次调用是否使用缓存数据?在PHP中,有一个名为clearstat

在RUnit测试中,我有以下代码片段:

checkTrue(!file.exists(fname))
doSomething()
#cat(fname);print(file.info(fname))
checkTrue(file.exists(fname))
第二次调用checkTrue()失败,即使
doSomething()
创建了一个文件。我已经确认文件在那里,上面显示了注释掉的行


因此,我想知道对
file.exists
的第二次调用是否使用缓存数据?在PHP中,有一个名为
clearstatcache
的函数可以阻止这种情况的发生。有一个R等价物吗?(或者,也许有人知道R从不缓存stat调用的结果?

文件。exists
不缓存stat调用的结果,因此没有与PHP的
clearstatcache
等效的方法。(旁白:这也意味着过度使用调用
file.exists
,或者任何
stat
函数都可能会降低性能。)

从R3.0.1开始,
file.exists
使用内部方法。如果您按照源代码进行操作,最终将调用sysutils.c中的
R\u FileExists

Rboolean R_FileExists(const char *path)
{
    struct stat sb;
    return stat(R_ExpandFileName(path), &sb) == 0;
}

(在Windows上,它使用了一个调用,我刚刚确认该调用也不会进行缓存。)

我也尝试过使用
fname,如果您有足够的能力创建单元测试,那么您的
doSomething
函数不应该将
fname
作为参数,而不是将其作为全局变量使用吗?谢谢@flodel的检查。我的问题是关于清除
file.exists
的stat缓存,作为对代码进行故障排除的工具;不是关于如何编写单元测试。如果清除stat缓存没有帮助,而且我也没有主意了,我将返回一个可复制的示例。(顺便说一句,
doSomething
正在从数据创建文件名;单元测试正在测试它正在生成预期的文件名,以及其他!)好吧,我想暗示的是,
file.exists
可能不使用缓存的数据,但您做了一些错误的事情。我很高兴被证明是错的,但为此,您需要为我们提供一个可复制的示例。@flodel我意识到它一定是将我的问题标记为“runit”,这导致了混淆(我也没有问为什么我对file.exists的第二次调用返回false;我问的是是否存在与clearstatcache等效的R。)总之,我下载了源代码并设法自行回答。