简体   繁体   English

R Markdown使用动态字符串扩展:无法启动png()设备时出现错误,没有明确的原因有时

[英]R Markdown Expanding with Dynamic String: Error unable to start png() device Shows Up Occasionally Without Clear Reason

I have this code in my dummy markdown script. 我的虚拟markdown脚本中有此代码。

<!--- add tests from dynamic strings --> 
`r paste(knit(text = expand_string), collapse = '\n')`

The string is generated in a main script: 该字符串是在主脚本中生成的:

generate_expand_string <- function(reported_test)
{

     exp_str <- paste0(
          '<h2>',
          reported_test,
          '</h2>',
          '\n',
          '<br>',
          '\n```{r ',
          paste0(reported_test, '_charts'),
          ', echo = F, fig.width = 14, fig.height = 12, fig.align = "center", message = F, warning = F}\n\n',
          'current_test <- ',
          '"',
          reported_test,
          '"',
          '\n\n',
          'if(length(indicator_charts[[current_test]]) > 0) { for(i in 1:length(indicator_charts[[current_test]])) { print(indicator_charts[[current_test]][[i]]) } };',
          '\n\n```',
          '\n',
          '<br>',
          '\n```{r ',
          paste0(reported_test, '_table'),
          ', results = "asis", echo = F}\n\n',
          'current_test <- ',
          '"',
          reported_test,
          '"',
          '\n\n',
          'kable(indicator_tables[[current_test]], align = rep("l", times = ncol(indicator_tables[[current_test]])));',
          '\n\n```',
          '\n\n'
     )

     return(exp_str)

}

And I run markdown inside the main script: 我在主脚本中运行markdown:

rmarkdown::render(
               paste0(
                    getwd(),
                    '/',
                    'dfsdsvcg/',
                    dfsfdsfdf
               ),
               output_file = paste0(
                    gsub(' ', '_', reported_indicator),
                    entity_indicator_report_file_name
               ),
               output_dir = out_dir
          )

I actually checked the existence of a folder where the png images are temporally stored: 我实际上检查了临时存储png图像的文件夹的存在:

<img src="S:\dfdfdf\dffdfd\debug\detailed\entities\September_2017\15_September_2017\thtthththef-addons\bwagfewcdvfe_files/figure-html/njebgkrded_charts-1.png" width="1344" style="display: block; margin: auto;" />

Looks like this. 看起来像这样。 There are the images. 有图像。 And this error happens 1 / 500 times as I generate the pages in a loop. 当我循环生成页面时,此错误发生1/500次。

Question: what do you think could cause it? 问题:您认为会导致什么?

I have a guess when this happens: the path length to image becomes 200+ characters long. 当发生这种情况时,我有一个猜测:图像的路径长度变成200个字符以上。 I can try make it shorter. 我可以尝试将其缩短。

Answer (apparently the cause of the bug fixing which worked for me): if the path length to images exported from a listed ggplot object as png files and stored temporally in a report directory becomes larger than n elements (around 200) the report generation in Markdown fails. 答案 (显然是错误修复的原因对我有用):如果从列出的ggplot对象作为png文件导出并临时存储在报告目录中的图像的路径长度大于n个元素(大约200个),则生成的报告降价失败。 Take care about your output file name lengths. 注意输出文件名的长度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:无法启动 png() 设备 - Error : Unable to start png() device jupyter 中的 r 图形 - 无法启动 png() 设备 - r graphs in jupyter - unable to start png() device R无法启动设备PNG - 功能()对于PNG是否为TRUE? - R unable to start device PNG - capabilities() has TRUE for PNG? 绘制编织错误:“无法启动 png() 设备” - Plot knitting error : “unable to start png() device” 无法导出绘图:R 代码执行错误/无法启动 png() 设备 - Unable to export plot: R code execution error/ unable to start png() device R Shiny 运行几个小时后无法启动 png 设备 - R Shiny unable to start png device after running a few hours ggsave() 失败并在 png_dev(..., res = dpi, units = "in") 中出现错误:无法启动 png() 设备 - ggsave() fails with Error in png_dev(..., res = dpi, units = "in") : unable to start png() device sp_execute_external_script R 脚本'无法启动 png() 设备' - sp_execute_external_script R script 'unable to start png() device' R包编织程序无法打开png()设备 - R package knitr unable to open png() device 这是什么错误; “(函数(文件名 =“Rplot%03d.png”,宽度 = 480,高度 = 480,:无法启动 png() 设备)中的错误? - What is this error; "Error in (function (filename = "Rplot%03d.png", width = 480, height = 480, : unable to start png() device"?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM