targets - object not found, even though it's loadable

51 views Asked by At

I've been trying to debug this problem for a while now, but I'm unable to figure out why it's happening.

tar_plan(
  tar_target(
    rctd_seurat_object_file,
    here::here(config$datadir, "pdac_tempus_rctd.rds"),
    format = "file"
  ),
  rctd_seurat_object = readRDS(rctd_seurat_object_file),
  original_metadata = [email protected],

  # Save the updated Seurat object
  tar_target(
    pdac_tempus_file,
    update_seurat_object(
      rctd_seurat_object
      here::here(config$outdir, "pdac_tempus.rds")
    ),
    format = "file"
  ),
  pdac_tempus <- readRDS(pdac_tempus_file),
  # metadata <- [email protected]
)

Here, for rctd_seurat_object_file, I'm pointing to a file, and loading that into rctd_seurat_object. I then use the update_seurat_object function to process and save the updated object into the path provided, and return the path to the output file from the function. That is saved in pdac_tempus_file. Now, when I try to call the readRDS on the pdac_tempus_file, just as I was doing before for rctd_seurat_object, it's throwing object pdac_tempus_file not found error.

I've tried loading that using tar_load(pdac_tempus_file) and it's being loaded successfully, and points to the correct output file. But I have no idea why it's not working in the above case.

Can anyone point me to some helpful documentation or guide me on how to fix this issue? Thanks.

1

There are 1 answers

0
cpauvert On

In order to help people help you, I would suggest to make sure to provide a reproducible example: see recommendations for R related questions.

That being said, it seems from your code that your issue is that you are mixing up two types of syntax to specify your targets workflow:

  1. using tar_plan() that expects stepB = do_something(stepA)
  2. using tar_target() that expects a different organization.

The {targets} user manual has extensive documentation and examples of good practices. Especially, the External files example is worth trying out with your case.

At the end of your file, you are accessing the RDS file like in standard R instead of using the targets approach (see https://books.ropensci.org/targets/projects.html#sharing-targets)

Best,