Skip to content

Commit

Permalink
using the number of rows in the structural metadata df to determine m…
Browse files Browse the repository at this point in the history
…etadata expansion
  • Loading branch information
collinschwantes committed Dec 9, 2024
1 parent deb0938 commit a6e5313
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions R/modify_frictionless_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#' # update structural metadata
#' write.csv(data_codebook,"my/codebook.csv", row.names = FALSE)
#'
#' data_codebook_updated <- read.csv(""my/codebook.csv"")
#' data_codebook_updated <- read.csv("my/codebook.csv")
#'
#' # create frictionless package - this is done automatically with the
#' # deposits package
Expand Down Expand Up @@ -61,9 +61,24 @@ expand_frictionless_metadata <- function(structural_metadata,

## build up schema based on structural metadata

for(idx in 1:length(my_data_schema$fields)){
# for each row, update the schema
for(idx in 1:nrow(structural_metadata)){
# item to build out
x <- my_data_schema$fields[[idx]]
## row may not exist in the original data.
x <- tryCatch(
expr = {
## get the fields item we want to update
my_data_schema$fields[[idx]]
},
error = function(e){
## use the first index item
msg<- sprintf("Adding %s to frictionless metadata",structural_metadata$name[[idx]])
message(msg)
my_data_schema$fields[[1]]
}
)


for(idy in 1:length(structural_metadata)){

y <- structural_metadata[idx,idy][[1]]
Expand All @@ -85,6 +100,7 @@ expand_frictionless_metadata <- function(structural_metadata,
my_data_schema$fields[[idx]] <- x
}


if(prune_datapackage){
my_data_schema <- prune_datapackage(my_data_schema,structural_metadata)
}
Expand Down
2 changes: 1 addition & 1 deletion man/expand_frictionless_metadata.Rd

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

0 comments on commit a6e5313

Please sign in to comment.