inbo / camtraptor

Camtraptor is an R package to read, explore and visualize Camera Trap Data Packages (Camtrap DP)
https://inbo.github.io/camtraptor/
MIT License
10 stars 2 forks source link

Allow read_camtrap_dp() to read from URL #57

Closed peterdesmet closed 2 years ago

peterdesmet commented 3 years ago
> dp <- read_camtrap_dp("https://zenodo.org/record/5590881/files/datapackage.json")
Error: Can't find file at `https://zenodo.org/record/5590881/files/datapackage.json/datapackage.json`.

datapackage supports reading from URL. It would be nice if this is supported by read_camtrap_dp() as well.

damianooldoni commented 3 years ago

I will. Although this is not something specific of camtrap-dp 0.1.6 I think it's still useful to get it done while working on such update.

damianooldoni commented 2 years ago

The problem is due to file.path(path, "datapackage.json") in read_camtrap_dp() function (L45):

# read files
  package <- read_package(file.path(path, "datapackage.json"))

Possible solutions:

  1. path arg points to the path of datapackage.json instead of the folder containing it. Maybe change the name of the arg, from path to file (making path deprecated and pointing to file) as this is the name of the argument in datapackage::read_package? This would make camtrap_dp very similar to the underlying package datapackage
  2. if path starts with http then package <- read_package(path). Other ways to detect automatically that path is an URL instead of a file path?
  3. add extra argument url to the function: default FALSE. If FALSE read_package(file.path(path, "datapackage.json")), if TRUE: package <- read_package(path)

I vote for the first solution 😄 @peterdesmet, @jimcasaer : which one do you vote for?

peterdesmet commented 2 years ago

Yes, option 1: make new parameter file. deprecate path, but keep its current behaviour to append with datapackage.json.