如何在 macOS 上使用文件选择对话框在 R 中保存文件?

huangapple go评论66阅读模式
英文:

How to use the file chooser dialog to save a file in R on macOS?

问题

有人知道在Mac上用"choose.dir"导出我的生成的栅格数据为tif格式的解决方案吗?替换"file.choose"不起作用,不幸的是。

请参考下面的代码部分:

terra::writeRaster(kmeans_raster,
  filename = base::paste0(utils::choose.dir,'/sentinel_kmeans.tif'))

谢谢帮助!

我尝试使用"file.choose"和"file.create"。

我尝试使用包'rJava' --> library("rJava")
操作无法完成。无法找到Java运行时。请访问http://www.java.com了解安装Java的信息。

错误: 加载包或命名空间“rJava”时出错:
 .onLoad in loadNamespace() for 'rJava' failed, Details:
  调用: fun(libname, pkgname)
  错误: 找不到JVM库'NA/lib/server/libjvm.dylib'
安装Java并/或检查JAVA_HOME(如有疑问,请勿设置,它将被检测)
> 
英文:

does anyone know a solution for "choose.dir" for Mac to export my builded raster as tif data. Exchanging "file.choose" didn't work unfortunately.

See the column code below:

terra::writeRaster(kmeans_raster,
  filename = base::paste0(utils::choose.dir,'/sentinel_kmeans.tif'))

Thank you for help!

I tried to use "file.choose" and file.creat"

I tried to use package 'rJava' --> library("rJava")
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.

Fehler: Laden von Paket oder Namensraum für ‘rJava’: fehlgeschlagen
 .onLoad in loadNamespace() für 'rJava' fehlgeschlagen, Details:
  Aufruf: fun(libname, pkgname)
  Fehler: JVM could not be found
Zusätzlich: Warnmeldungen:
1: In system("/usr/libexec/java_home", intern = TRUE) :
  Ausführung von Kommando '/usr/libexec/java_home' ergab Status 1
2: In fun(libname, pkgname) :
  Cannot find JVM library 'NA/lib/server/libjvm.dylib'
Install Java and/or check JAVA_HOME (if in doubt, do NOT set it, it will be detected)
> 

答案1

得分: 1

你可以执行以下操作:

filename <- file.path(utils::choose.dir(), "sentinel_kmeans.tif")
terra::writeRaster(kmeans_raster, filename, overwrite=TRUE)

我不知道你为什么认为 "rJava" 在这里相关。但它无法加载的原因似乎是你没有安装Java。

英文:

You can do

filename &lt;- file.path(utils::choose.dir(), &quot;sentinel_kmeans.tif&quot;)
terra::writeRaster(kmeans_raster, filename, overwrite=TRUE)

I do not know why you think "rJava" is relevant here. But the reason it won't load seems to be that you do not have Java installed.

huangapple
  • 本文由 发表于 2023年6月1日 19:56:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76381610.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定