ubuntu终端和来自R的呼叫之间的ulimit不同



我正试图在R中使用mapboxapi::tippecanoe()创建地图框瓦片。不幸的是,我的工作计算机运行的是Windows 10,这使我的工作变得非常复杂。Tippecanoe是一个Unix可执行文件,所以我下载并安装了Ubuntu,并在Linux的Windows子系统上运行它。为了启动tippecanoe,我必须编辑mapboxapi::tippecanoe()的源代码,以便将参数传递给WSL。然后我遇到了一个问题,Tippecanoe会给我一个错误,说它无法打开数据库文件。对Github的一些研究让我相信这与Ubuntu中打开文件的数量限制有关。经过大量挖掘,我能够在我的ubuntu终端上将ulimit -n增加到65535。一旦我启动Ubuntu,如果我输入ulimit -n,我就会得到65535。然而,当我调用"sytem2"("wsl","ulimit-n"(时,我得到的默认值是1024。我以为这是由于R在Ubuntu中调用的用户,但运行system2("wsl"、"whoami"(返回了我增加了其硬文件和软文件限制的用户名。我真的被难住了。很抱歉没有粘贴一个可复制的例子,但我不知道如何为这种情况制作一个。任何帮助都将不胜感激。谢谢

经过大量的修补,这主要是一个简单的R代码问题。ulimit问题可能仍然是个问题,但实际上我需要修复mapboxapi::tippecanoe()中的R代码。因为mapboxapi::tippecanoe()使用system()命令来调用tippecanoe,所以我不仅需要使用system2("wsl", "- d Ubuntu -lc 'tippecanoe <arguments to tippecanoe>'")通过登录shell更改调用以调用wsl,而且还需要将R发送给tippecanoe的路径更改为linux路径,而不是Window路径。如果其他人对此有问题,下面是经过调整的mapboxapi::tippecanoe()命令代码,它实际上对我有效:

tippecanoe2<-function (input, output, layer_name, min_zoom = NULL, 
max_zoom = NULL, drop_rate = NULL, overwrite = TRUE, other_options = NULL, 
keep_geojson = FALSE) 
{

check_install <- system2("wsl", "tippecanoe -v") == 0
linux_dir<-paste(getwd(), layer_name, sep="/")#make a directory in your linux directory for the .mbtiles
parsed<-strsplit(linux_dir, split="/") #parse the windows directory path
n<-length(parsed[[1]])
dir_out<-paste("",parsed[[1]][n-1], parsed[[1]][n], sep="/") #construct the linux directory path
dir.create(linux_dir)
op<-options(useFancyQuotes = FALSE)
if (!check_install) {
rlang::abort(c("tippecanoe is not installed or cannot be found by the application you are using to run mapboxapi.", 
"If you haven't installed tippecanoe, please visit https://github.com/mapbox/tippecanoe for installation instructions.", 
"If you have installed tippecanoe, run `Sys.getenv('PATH')` and make sure your application can find tippecanoe. If it cannot, adjust your PATH accordingly."))
}
opts <- c()
if (!is.null(min_zoom)) {
opts <- c(opts, sprintf("-Z%s", min_zoom))
}
if (!is.null(max_zoom)) {
opts <- c(opts, sprintf("-z%s", max_zoom))
}
if (is.null(min_zoom) && is.null(max_zoom)) {
opts <- c(opts, "-zg")
}
if (!is.null(drop_rate)) {
opts <- c(opts, sprintf("-r%s", drop_rate))
}
else {
opts <- c(opts, "-as")
}
if (overwrite) {
opts <- c(opts, "-f")
}
collapsed_opts <- paste0(opts, collapse = " ")
if (!is.null(other_options)) {
extra_opts <- paste0(other_options, collapse = " ")
collapsed_opts <- paste(collapsed_opts, extra_opts)
}
dir <- linux_dir
if (any(grepl("^sf", class(input)))) {
input <- sf::st_transform(input, 4326)
if (is.null(layer_name)) {
layer_name <- stringi::stri_rand_strings(1, 6)
}
if (keep_geojson) {
outfile <- paste0(layer_name, ".geojson")
path <- file.path(dir_out, outfile)
sf::st_write(input, path, quiet = TRUE, delete_dsn = TRUE, 
delete_layer = TRUE)
}
else {
tmp <- tempdir("//wsl$/Ubuntu/tmp")#Here you would need to tweak to the file path for your linux distribution's temporary directory
tempfile <- paste0(layer_name, ".geojson")
path <- file.path(tmp, tempfile)
sf::st_write(input, path, quiet = TRUE, delete_dsn = TRUE, 
delete_layer = TRUE)
}
call <- sprintf("tippecanoe -o %s/%s %s %s", dir_out, output, 
collapsed_opts, path)
call2<-paste("-d Ubuntu /bin/bash -lc", sQuote(call, op), sep=" ")
system2("wsl", call2)
}
else if (inherits(input, "character")) {
if (!is.null(layer_name)) {
collapsed_opts <- paste0(collapsed_opts, " -l ", 
layer_name)
}
call <- sprintf("tippecanoe -o %s/%s %s %s", dir_out, output, 
collapsed_opts, input)
call2<-paste("-d Ubuntu /bin/bash -lc", sQuote(call, op), sep=" ")
system2("wsl", call2)
}
}

最新更新