在 {targets} 管道中使用 {terra} 加载栅格数据

问题描述 投票:0回答:0

我正在尝试使用 terra 包在目标管道中加载栅格。

_targets.R 文件如下所示:

# Created by use_targets().
# Follow the comments below to fill in this target script.
# Then follow the manual to check and run the pipeline:
#   https://books.ropensci.org/targets/walkthrough.html#inspect-the-pipeline # nolint

# Load packages required to define the pipeline:
library(targets)
# library(tarchetypes) # Load other packages as needed. # nolint

# Set target options:
tar_option_set(
  packages = c(
    "tidyverse",
    "terra",
  ), # packages that your targets need to run
  format = "rds" # default storage format
  # Set other options as needed.
)

# tar_make_clustermq() configuration (okay to leave alone):
options(
  clustermq.scheduler = "multiprocess"
)

# tar_make_future() configuration (okay to leave alone):
# Install packages {{future}}, {{future.callr}}, and {{future.batchtools}} to allow use_targets() to configure tar_make_future() options.

# Run the R scripts in the R/ folder with your custom functions:
tar_source()
# source("other_functions.R") # Source other scripts as needed. # nolint

# Replace the target list below with your own:
list(
  ## Load all data in R/load_data.R
  tar_target(esg_rast_file, "data/ESGs/ESGs.tif", format="file"),
  tar_target(esg_rast_data, terra::rast(esg_rast_file))
)

我的输出是这样的:

r$> library(targets)

r$> tar_make()
• start target esg_rast_file
• built target esg_rast_file [6.42 seconds]
• start target esg_rast_data
• built target esg_rast_data [0.05 seconds]
• end pipeline [7.96 seconds]
 
r$> tar_load(esg_rast_data)
NULL value passed as symbol address
r$> esg_rast_data
class       : SpatRaster
Error in x@ptr$nrow() : external pointer is not valid

这是应该发生的事情吗?难道我做错了什么?我似乎无法在网上找到有关这些错误的任何信息。我也无法加载 sf .shp 数据。好像我错过了什么。

r target
© www.soinside.com 2019 - 2024. All rights reserved.