Skip to content

Vector with 1 element should stay a vector when writing to .json (and not become a string) #272

Open
@sannegovaert

Description

@sannegovaert

When there is 1 reference, this should look like this in datapackage.json:

"references": ["my_reference"]

However, that is not the case when writing a Data Package.

library(camtrapdp)
x <- example_dataset()
x$references <- c("my_reference")
write_camtrapdp(x, directory = "references_as_string")

In datapackage.json, references then looks like this:
"references": "my_reference"

The IPT does not recognize this, as the square brackets are missing.
It does work when a second (empty element) is added:

x$references <- c("my_reference", "")
write_camtrapdp(x, directory = "references_as_vector")

In datapackage.json, references then looks like this:
"references": ["my_reference", ""]
The IPT can handle this, but it genereates an empty field for reference.

unlink("references_as_string", recursive = TRUE)
unlink("references_as_vector", recursive = TRUE)

Created on 2024-11-21 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions