"Temporary name too long" 使用 Rnotebook 意外出现的错误

"Temporary name too long" error that appears unexpectedly using Rnotebook

在使用 rnotebook 时,我在通过 broom 获取线性回归模型的输出时遇到以下错误。

这是我遇到的一个虚拟例子:

    N <- 100
a <- rnorm(N)
b <- a + rnorm(N)
df1 <- data.frame(a, b)

lModel <- lm(b ~ a, df1)

summary(lModel)

然后如果我想获得 tidy(lModel) 的输出,我会得到错误:

Error in tempfile(pattern = "_rs_rdf_", tmpdir = outputFolder, fileext = ".rdf") : temporary name too long

问题是我不久前使用了 broom 的 tidy() 函数并得到了输出。我想知道可能是什么问题,以及如何解决它。

这是上述错误的回溯:

Error in tempfile(pattern = "_rs_rdf_", tmpdir = outputFolder, fileext = ".rdf") : temporary name too long
4.
tempfile(pattern = "_rs_rdf_", tmpdir = outputFolder, fileext = ".rdf")
3.
overridePrint(o$x, o$options, o$className, o$nRow, o$nCol)
2.
print.data.frame(x)
1.
function (x, ...) UseMethod("print")(x)

非常感谢。

在 Windows 系统上,当目录嵌套的级别过多时会出现此错误。Windows API has a maximum path length of 260 characters

Maximum Path Length Limitation In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character. For example, the maximum path on drive D is "D:\some 256-character path string" where "" represents the invisible terminating null character for the current system codepage. (The characters < > are used here for visual clarity and cannot be part of a valid path string.)

这很容易避免。只需调整您的工作目录,或您保存临时文件的结构。您的文件名太长,或者您的目录嵌套太深,因此路径超出了 Windows' 路径限制。

顺便说一句,在 Unix 系统上,此最大路径明显更长,但文件名的最大长度为 255 个字符。

这可以通过 Windows10 上的注册表更改来解决。

  1. 在开始菜单中搜索regedit打开注册表编辑工具
  2. 导航到 Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
  3. LongPathsEnabled0 更改为 1

现在将忽略 256 个字符的限制。

2018 年 8 月 4 日更新:如果您的 R 工作目录位于 Google Drive File Stream 文件夹中,则仍然会执行限制。这是因为 GDFS 是一个虚拟驱动器,有自己的限制。