1

I am learning to use targets within my current research project. I am still at the beginning of my data processing (and associated pipeline) but I get the following error when I try to use targets::tar_make():

> targets::tar_make()
✔ skip target raw_tits
• start target nnestling_data
ℹ Using "','" as decimal and "'.'" as grouping mark. Use `read_delim()` for more control.
✖ error target nnestling_data
• end pipeline: 1.19 seconds
Error : _paths_ missing files: Table exported to D:/fmartin/Mes documents/projects/pubprivlands/analyses/ppl.tits/output/tables/tits_nestling_data.csv
✖ Problem with the pipeline.
ℹ Show errors: tar_meta(fields = error, complete_only = TRUE)
ℹ Learn more: https://books.ropensci.org/targets/debugging.html
Error:
! problem with the pipeline.

I truly don't understand why it doesn't work since there is no missing file. Here's how my current _targets.R looks like:

list(
  # Make the workflow depends on the raw data file
  targets::tar_target(raw_data_file, here::here("mydata", "ppl_dijon_tits_data.csv"),
             format = "file"),
  # Read the data and return a data.frame
  targets::tar_target(raw_tits, ppl.tits::import_raw_tits_data()),
  # Export the nestling aggregated data table
  targets::tar_target(nnestling_data, ppl.tits::export_nestling_aggreg(), format = "file")
  )

And the simple export function I'm calling in my last targets::tar_target():

export_nestling_aggreg <- function(){
  aabb <- ppl.tits::aggreg_by_nest()
  readr::write_csv2(x = aabb, file = here::here("output", "tables", "tits_nestling_data.csv"))
  return(paste("Table exported to", here::here("output", "tables", "tits_nestling_data.csv"), sep = " "))
}

Could someone help me figure this one out?

Fanfoué
  • 165
  • 11
  • The file it is looking for is `D:/path/to/my/file.csv`, which I don't see in your code, whereas `export_nestling_aggreg()` returns a different CSV file path. Did you forget to save an R script you were editing? – landau Jul 29 '22 at 20:24
  • @landau I modified the code posted here to hide the personal information of my computer, hence the `D:/path/to/my/file.csv` (the true path indeed ends with `output/tables/tits_nestling_data.csv` as shown in my custom function). There is no mistake here and all files are saved, but I will edit my question to put the true paths in case I made mistakes (thank you, btw). – Fanfoué Aug 01 '22 at 08:15
  • Ah, I think it’s the “Table exported to” part of the string. The function writing the file should return exactly the path written, without any extra text. As it stands, {targets} thinks your file is in a folder called “Table exported to D:/fmartin/“. – landau Aug 01 '22 at 09:06
  • I'm a bit puzzled because I already tried to remove this part of code but it did not worked at the time and now... it does! I must have missed something. Thank you for your help! :) – Fanfoué Aug 01 '22 at 09:16
  • @landau, I just noticed another problem. When I try `targets::tar_make()`, the code now runs (thanks to you) but it does not actually export the table as requested, it simply writes the path to the folder. I noticed it because I updated my input dataset (i.e. ppl_dijon_tits_data.csv) but when I ran `targets::tar_make()`, it did not update the exported table as it should have (that's the whole point of `targets`, keeping track of changes and updating only the parts affected by the changes, right?). Any idea why? – Fanfoué Aug 03 '22 at 11:14
  • 1
    Did the content of the input dataset change, or did you make a trivial change to the input file? Because if the data frame you get out of that has the same hash as last time, then {targets} won’t actually consider it a change even if the timestamp changed. – landau Aug 03 '22 at 11:54
  • The number of rows is the same but I corrected some mistakes in the cells. – Fanfoué Aug 03 '22 at 12:25
  • Hard to say because I don’t have your data, so I can’t run your pipeline. If you reproduce the same behavior with a dataset I can access, I may have better advice. – landau Aug 03 '22 at 20:32
  • You can clone my project if you want (https://github.com/mrelnoob/ppl.tits). This is an R package that I am developing to help me organise the data analysis process linked to my research project. However, as I am a mediocre R user and since I hadn't the time to properly read the {targets} documentation (sorry), you'll probably find a lot of clumsy programming. The good point is that I write my R files with much comments to help future me (and others) reproduce my work so it's quite straightforward. – Fanfoué Aug 09 '22 at 09:18
  • I ran https://github.com/mrelnoob/ppl.tits/commit/32f1b9f78afd9f28dfc2a7930692f560cc325f70 with no issue (after installing your package). Looks like you fixed the error since we last spoke. – landau Aug 15 '22 at 12:55
  • I did nothing of the sort, at least not on purpose, but I'm glad as long as it works. I should truly read the {targets} documentation. Thanks anyway! – Fanfoué Aug 16 '22 at 09:36

0 Answers0