dir.create 中的递归参数是什么意思?
What does the recursive argument mean in dir.create?
我正在尝试使用 dir.create() 函数来创建嵌套文件夹“folder2”和“folder3”。
解决方案是:
dir.create(file.path("folder2", "folder3"), recursive = TRUE)
编辑: ?dir.create
的解释是
recursive logical. Should elements of the path other than the last be created? If true, like the Unix command mkdir -p.
递归 属性的用途是什么?
从 'mkdir -p' 中提取你的问题,并进行解释 here:
如果您的 'folder2' 包含父文件夹,则需要先创建这些文件夹,否则创建函数将无法在路径末尾创建最终文件(不会有任何地方这么说吧,因为完整路径还不存在)。
假设 'folder2' 是 'a/b/c/'。要创建文件夹 'c',您首先需要创建文件夹 'b'。但是对于 'b' 你首先需要 'a'。所以所有的 parent 文件夹都需要在最终的 child 文件夹(或文件)之前创建。
'recursion'指的是'stepwise repeating again and again'。 [使 'a' 然后 'b' 最后 'c']
假设您的工作目录中有一个 Temp
文件夹。如果您想在 Temp
.
中的文件夹中创建文件夹
dir.create('Temp/A/B/')
这将失败,因为文件夹 A
不存在。然而,
dir.create('Temp/A/B/', recursive = TRUE)
将工作并在文件夹 A
中创建一个文件夹 B
。
我正在尝试使用 dir.create() 函数来创建嵌套文件夹“folder2”和“folder3”。
解决方案是:
dir.create(file.path("folder2", "folder3"), recursive = TRUE)
编辑: ?dir.create
的解释是
recursive logical. Should elements of the path other than the last be created? If true, like the Unix command mkdir -p.
递归 属性的用途是什么?
从 'mkdir -p' 中提取你的问题,并进行解释 here:
如果您的 'folder2' 包含父文件夹,则需要先创建这些文件夹,否则创建函数将无法在路径末尾创建最终文件(不会有任何地方这么说吧,因为完整路径还不存在)。
假设 'folder2' 是 'a/b/c/'。要创建文件夹 'c',您首先需要创建文件夹 'b'。但是对于 'b' 你首先需要 'a'。所以所有的 parent 文件夹都需要在最终的 child 文件夹(或文件)之前创建。
'recursion'指的是'stepwise repeating again and again'。 [使 'a' 然后 'b' 最后 'c']
假设您的工作目录中有一个 Temp
文件夹。如果您想在 Temp
.
dir.create('Temp/A/B/')
这将失败,因为文件夹 A
不存在。然而,
dir.create('Temp/A/B/', recursive = TRUE)
将工作并在文件夹 A
中创建一个文件夹 B
。