仅当从RStudio调用时才失败

问题描述

我在装有Ubuntu 20.04的计算机上使用RStudio版本1.3.1093。我的R版本是4.0.3。

当我从RStudio调用以下代码行时,出现了意外的行为:

console.log(items.filter(isItemOfCategory(Category.Fruit)).map(x => x.taste)); // ["sour"]
console.log(items.filter(isItemOfCategory(Category.Drink)).map(x => x.price)); // [30]
console.log(items.filter(isItemOfCategory(Category.Animal)).map(x => x.name)); // ["Fluffy"]

它失败并显示以下消息:

filter()

如果我从RStudio终端(system("soffice --headless --convert-to xlsx --outdir files/ files/EGP.xlsb") 调用“ naked”命令,则错误完全相同:

/usr/lib/libreoffice/program/javaldx: error while loading shared libraries: libreglo.so: cannot open shared object file: No such file or directory
Warning: Failed to read path from javaldx
/usr/lib/libreoffice/program/soffice.bin: error while loading shared libraries: libreglo.so: cannot open shared object file: No such file or directory
Warning message:
In system("soffice --headless --convert-to xlsx --outdir files/ files/EGP.xlsb") :
  error in running command

但是,如果我从终端进行相同的呼叫,它将正常工作并产生预期的输出

soffice --headless --convert-to xlsx --outdir files/ files/EGP.xlsb

我遵循Playground link to code中的建议,认为需要更新user@machine:~/Right/Path/To/File$ soffice --headless --convert-to xlsx --outdir files/ files/EGP.xlsb /usr/lib/libreoffice/program/javaldx: error while loading shared libraries: libreglo.so: cannot open shared object file: No such file or directory Warning: Failed to read path from javaldx /usr/lib/libreoffice/program/soffice.bin: error while loading shared libraries: libreglo.so: cannot open shared object file: No such file or directory ,但问题无法解决

RStudio是否缺少查找libreoffice库的路径,这对于系统是显而易见的(因为终端在查找它们时没有问题)?我该如何解决? 谢谢!

解决方法

在此处关注 Roah 评论:shared library issue with the system function in R

在 R 脚本中添加 Sys.setenv 位对我有用:

Sys.setenv(LD_LIBRARY_PATH = "/usr/lib/libreoffice/program/")
system('soffice --convert-to odt table.html')