循环中的rmarkdown :: render()-无法分配大小的向量 [英] rmarkdown::render() in a loop - cannot allocate vector of size

查看:181
本文介绍了循环中的rmarkdown :: render()-无法分配大小的向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆包含Rmd文件的目录,这些目录将被编译成HTML.每个对rmarkdown::render的调用都包含一个很大的params列表.当我分别渲染Rmd文件时,一切正常.

I have a bunch of directories with Rmd files to be compiled into HTML. Each call to rmarkdown::render includes a large list of params. Everything works fine when I render the Rmd files individually.

但是,当我执行一个遍历目录并构建HTML文件的函数时,它在完成9个函数后就会崩溃(它不是引起问题的特定Rmd,无论顺序如何,它都会在9日崩溃).

However, when I execute a function that loops over the directories and builds the HTML files it crashes after it has completed nine (it is not a specific Rmd causing the problem, it crashes on the 9th regardless of the order).

错误回溯的相关部分是:

The relevant part of the error traceback is:

Error: cannot allocate vector of size 38.4 Gb

8. knitr::knit_meta_add(old_knit_meta, attr(old_knit_meta, "knit_meta_id")) 

7. rmarkdown::render(input = RMDfile, output_file = RMDfileout, 
        output_format = output, output_dir = dir, param = params, 
        quiet = quiet)

问题似乎是由rmarkdown::render中的此行引起的:

The problem appears to be caused by this line in rmarkdown::render:

 on.exit({
    knit_meta_reset()
    if (length(old_knit_meta)) {
      knitr::knit_meta_add(old_knit_meta, attr(old_knit_meta, 
                                               "knit_meta_id"))
    }
  }, add = TRUE)

在我看来,先前调用中的params已保存在元数据中,并且在函数中调用rmarkdown::render 9次后,它变得太大了.

It appears to me that the params from the previous calls are being saved in the meta-data, and is getting too large after rmarkdown::render is called 9 times in the function.

rmarkdown::knitr有一个knit_meta自变量,但帮助文档中说 "(供专家使用)由knitr生成的元数据",我不是knitr专家.

rmarkdown::knitr has a knit_meta argument, but the help documentation says "(For expert use) Meta data generated by knitr" and I'm no knitr expert.

Rmd文件彼此完全独立.有没有一种方法可以重置每次调用rmarkdown::render的针织机元数据?

The Rmd files are completely independent from each other. Is there a way to reset the knitr meta-data for each call to rmarkdown::render?

我希望有人可以为此提供快速修复或解决方法.如果没有,我将举一个例子来重现该问题.

I'm hoping someone can offer a quick fix or workaround for this. If not, I'll develop an example to reproduce the problem.

推荐答案

rmarkdown::render代码中研究了一段时间之后,我找到了解决方案.

After digging around in rmarkdown::render code for a while I've found a solution.

rmarkdown::render(input=file, etc)之前添加knitr::knit_meta(class=NULL, clean = TRUE)似乎可以解决问题.

Adding knitr::knit_meta(class=NULL, clean = TRUE) before rmarkdown::render(input=file, etc) seems to do the trick..

这篇关于循环中的rmarkdown :: render()-无法分配大小的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆