Skip to content

Set $schema as first attribute #358

Description

@peterdesmet

$schema should be the first property of package, resource, schema. That makes the JSON file easier to read.

  • When creating an object from scratch, that is easy. Just define it first. create_package(), create_schema and add_resource() already do this.
  • When manipulating an object that already has properties, it's harder (i.e. what the upgrade_ functions do). You need to use append() or alike.

The issue is that append() drops any custom attributes and class, which are required for functions that use that object.

library(frictionless)
p <- example_package()
attributes(p)
#> $names
#> [1] "name"      "id"        "licenses"  "version"   "created"   "spatial"  
#> [7] "temporal"  "resources"
#> 
#> $directory
#> [1] "/Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/library/frictionless/extdata/v1"
#> 
#> $class
#> [1] "datapackage" "list"

p <- append(p, list("$schema" = "just added"), after = 0)
attributes(p)
#> $names
#> [1] "$schema"   "name"      "id"        "licenses"  "version"   "created"  
#> [7] "spatial"   "temporal"  "resources"

Created on 2026-08-26 with reprex v2.1.1

TODO

  • Is there a way to solve this in purrr()? Note that prepend() (deprecated) has the same issue.
  • Is there a way to solve this without a helper function?
  • Should frictionless have its own append() function? See discussion at append() drops custom datapackage class #198
  • Once implemented, revert 036bb52

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

function:upgradeFunction upgrade_package(), upgrade_resource(), upgrade_schema()

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions