在使用适用于 macOS 的 GitHub Actions 进行测试之前如何安装 X11?

Dan*_*iel 8 x11 macos r cairo github-actions

我正在使用 GitHub Actions 测试 R 包,它在 Windows 和 Linux 上成功。

但是,它在 Mac OS 上失败,正如您在日志中看到的那样:

  Warning in grSoftVersion() :
    unable to load shared object '/Library/Frameworks/R.framework/Resources/modules//R_X11.so':
    dlopen(/Library/Frameworks/R.framework/Resources/modules//R_X11.so, 6): Library not loaded: /opt/X11/lib/libSM.6.dylib
    Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/modules/R_X11.so
    Reason: image not found
  Warning in cairoVersion() :
    unable to load shared object '/Library/Frameworks/R.framework/Resources/library/grDevices/libs//cairo.so':
    dlopen(/Library/Frameworks/R.framework/Resources/library/grDevices/libs//cairo.so, 6): Library not loaded: /opt/X11/lib/libXrender.1.dylib
    Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/grDevices/libs/cairo.so
    Reason: image not found
  Warning in png(filename = file, width = width, height = height, units = "in",  :
    failed to load cairo DLL
  Error in external_img(new_src, width = width, height = height) : 
    src must be a string starting with 'rId' or an image filename
  Calls: %>% ... <Anonymous> -> body_add_gg -> body_add_img -> external_img
  Execution halted
Run Code Online (Sandbox Code Playgroud)

我没有 Mac 电脑,将来也不打算这样做,所以我无法自己测试。

正如我在 mac 上看到的include cairo R,这可能是由于 X11 没有安装在测试机器上。

如何告诉 GitHub Actions 此代码依赖于 X11?

编辑:

这是我的 GitHub Actions 配置文件:link。添加此代码解决了问题:

  Warning in grSoftVersion() :
    unable to load shared object '/Library/Frameworks/R.framework/Resources/modules//R_X11.so':
    dlopen(/Library/Frameworks/R.framework/Resources/modules//R_X11.so, 6): Library not loaded: /opt/X11/lib/libSM.6.dylib
    Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/modules/R_X11.so
    Reason: image not found
  Warning in cairoVersion() :
    unable to load shared object '/Library/Frameworks/R.framework/Resources/library/grDevices/libs//cairo.so':
    dlopen(/Library/Frameworks/R.framework/Resources/library/grDevices/libs//cairo.so, 6): Library not loaded: /opt/X11/lib/libXrender.1.dylib
    Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/grDevices/libs/cairo.so
    Reason: image not found
  Warning in png(filename = file, width = width, height = height, units = "in",  :
    failed to load cairo DLL
  Error in external_img(new_src, width = width, height = height) : 
    src must be a string starting with 'rId' or an image filename
  Calls: %>% ... <Anonymous> -> body_add_gg -> body_add_img -> external_img
  Execution halted
Run Code Online (Sandbox Code Playgroud)

Lex*_* Li 7

Homebrew 位于 GitHub Actions 默认虚拟机上,

https://github.com/actions/virtual-environments/blob/main/images/macos/macos-10.15-Readme.md

所以你可以通过自制软件安装 X11

brew cask install xquartz
Run Code Online (Sandbox Code Playgroud)

https://formulae.brew.sh/cask/xquartz

在执行 R 测试之前。