Skip to content

Commit

Permalink
make schema and metadata df the same length
Browse files Browse the repository at this point in the history
  • Loading branch information
collinschwantes committed Dec 9, 2024
1 parent 2351d22 commit a052e78
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 32 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ohcleandat 0.3.12

* `expand_frictionless_metadata` can add and remove fields from the metadata depending
on the structural metadata supplied.

# ohcleandat 0.3.11

* obfuscate gps can now handle NAs
Expand Down
14 changes: 7 additions & 7 deletions R/create_structural_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
#'
#' The metadata table produced has the following elements
#'
#' `name` = The name of the field. This is taken as is from `data`.
#' `description` = Description of that field. May be provided by controlled vocabulary
#' `units` = Units of measure for that field. May or may not apply
#' `term_uri` = Universal Resource Identifier for a term from a controlled vocabulary or schema
#' `comments` = Free text providing additional details about the field
#' `primary_key` = `TRUE` or `FALSE`, Uniquely identifies each record in the data
#' `foreign_key` = `TRUE` or `FALSE`, Allows for linkages between data sets. Uniquely identifies
#' - `name` = The name of the field. This is taken as is from `data`.
#' - `description` = Description of that field. May be provided by controlled vocabulary
#' - `units` = Units of measure for that field. May or may not apply
#' - `term_uri` = Universal Resource Identifier for a term from a controlled vocabulary or schema
#' - `comments` = Free text providing additional details about the field
#' - `primary_key` = `TRUE` or `FALSE`, Uniquely identifies each record in the data
#' - `foreign_key` = `TRUE` or `FALSE`, Allows for linkages between data sets. Uniquely identifies
#' records in a different data set
#'
#'
Expand Down
16 changes: 13 additions & 3 deletions R/modify_frictionless_metadata.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#' Expand Frictionless Metadata with structural metadata
#'
#' Loops over elements in the structural metadata and adds them to frictionless
#' metadata schema. Will overwrite existing values.
#' Loops over elements in the structural metadata and adds
#' them to the frictionless metadata schema. Will overwrite existing values and
#' remove any fields from the datapackage metadata not listed in the structural
#' metadata.
#'
#' @param structural_metadata Dataframe. Structural metadata from
#' `create_structural_metadata` or `update_structural_metadata`
Expand Down Expand Up @@ -61,6 +63,11 @@ expand_frictionless_metadata <- function(structural_metadata,

## build up schema based on structural metadata

## drop fields that were removed from the structural metadata
if(nrow(structural_metadata) <= length(my_data_schema$fields)){
my_data_schema$fields <- my_data_schema$fields[1:nrow(structural_metadata)]
}

# for each row, update the schema
for(idx in 1:nrow(structural_metadata)){
# item to build out
Expand Down Expand Up @@ -101,6 +108,7 @@ expand_frictionless_metadata <- function(structural_metadata,
}


## prune the properties of items in the schema, does not remove fields
if(prune_datapackage){
my_data_schema <- prune_datapackage(my_data_schema,structural_metadata)
}
Expand All @@ -120,7 +128,7 @@ expand_frictionless_metadata <- function(structural_metadata,
}


#' Prune data pacakge
#' Prune field properties in a data package
#'
#' method to remove properties from the metadata for a dataset in a datapackage
#'
Expand Down Expand Up @@ -152,3 +160,5 @@ prune_datapackage <- function(my_data_schema, structural_metadata){

return(my_data_schema_pruned)
}


17 changes: 9 additions & 8 deletions man/create_structural_metadata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/expand_frictionless_metadata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/prune_datapackage.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions vignettes/data_examples/my_data.csv
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"date","measurement","measured_by","site_name","key"
2024-08-26,43,"Johana","c",1
2024-08-27,9,"Johana","c",2
2024-08-28,79,"Johana","c",3
2024-08-29,17,"Collin","a",4
2024-08-30,61,"Johana","e",5
2024-08-31,30,"Collin","b",6
2024-09-01,58,"Collin","a",7
2024-09-02,27,"Johana","d",8
2024-09-03,52,"Johana","d",9
2024-09-04,82,"Collin","e",10
date,measurement,measured_by,site_name,key
2024-08-26,43,Johana,c,1
2024-08-27,9,Johana,c,2
2024-08-28,79,Johana,c,3
2024-08-29,17,Collin,a,4
2024-08-30,61,Johana,e,5
2024-08-31,30,Collin,b,6
2024-09-01,58,Collin,a,7
2024-09-02,27,Johana,d,8
2024-09-03,52,Johana,d,9
2024-09-04,82,Collin,e,10

0 comments on commit a052e78

Please sign in to comment.