我正在尝试使用flextable将数据帧另存为图像文件,最终目的是将其绘制在ggplot对象旁边。这是代码示例:
library(flextable)
ft <- flextable( head( mtcars ) )
ft <- autofit(ft)
tf <- tempfile(fileext = ".png")
save_as_image(ft, tf)
返回以下错误:
Could not load file:///D:/Antonis/Documents/file:/C:/Users/Antonis/AppData/Local/Temp/RtmpmgSSYv/file2510dc77c47.html
Error in webshot::webshot(url = sprintf("file://%s", tf), file = path, :
webshot.js returned failure value: 1
In addition: Warning message:
In normalizePath(path.expand(path), winslash, mustWork) :
path[1]="file://C:\Users\Antonis\AppData\Local\Temp\RtmpmgSSYv\file2510dc77c47.html": The filename, directory name, or volume label syntax is incorrect
似乎文件路径不正确。我试图用setwd更改工作目录:
setwd("C:/Users/Antonis/AppData/Local/Temp/RtmpmgSSYv")
但错误仍然存在:
Could not load file:///C:/Users/Antonis/AppData/Local/Temp/RtmpmgSSYv/file:/C:/Users/Antonis/AppData/Local/Temp/RtmpmgSSYv/file25105e4f2c8b.html
Error in webshot::webshot(url = sprintf("file://%s", tf), file = path, :
webshot.js returned failure value: 1
In addition: Warning message:
In normalizePath(path.expand(path), winslash, mustWork) :
path[1]="file://C:\Users\Antonis\AppData\Local\Temp\RtmpmgSSYv\file25105e4f2c8b.html": The filename, directory name, or volume label syntax is incorrect
当我尝试通过tempfile命令设置路径时,也会发生同样的情况:
tf <- tempfile(tmpdir = "C:/Users/Antonis/AppData/Local/Temp/RtmpmgSSYv", fileext = ".png")
save_as_image帮助文件也没有提供任何见解。
以上代码非常通用,实际上是从博客文章中提取的,所以我的问题似乎是本地的。 有什么建议吗?