Skip to content

Commit f695eb0

Browse files
committed
Fix bf_export metadata extraction: use correct field names from registry flags
- Change f$provenance$wasGeneratedBy to f$wasGeneratedBy$useTest - Change f$position to f$wasGeneratedBy$assignPosition - Change f$description to f$comment - Add missing sign multiplication in floating-point decode (line 113) These fixes allow bf_export to correctly generate DataCite metadata.
1 parent 817e6e1 commit f695eb0

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

R/helpers.R

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
}
4545

4646
}
47+
if(is.null(bin)) bin <- 0
4748
bin <- paste0(bin, collapse = "")
4849

4950
return(bin)
@@ -489,9 +490,15 @@
489490
assertCharacter(x = protocol$description, len = 1, any.missing = FALSE)
490491
assertCharacter(x = protocol$encoding_type, len = 1, any.missing = FALSE)
491492
assertIntegerish(x = protocol$bits, len = 1, lower = 1)
492-
assertCharacter(x = protocol$test, len = 1, any.missing = FALSE)
493493
assertList(x = protocol$data)
494494

495+
# turn test string into function first, before validation
496+
if (is.character(protocol$test)) {
497+
protocol$test <- eval(parse(text = protocol$test))
498+
}
499+
500+
# protocol$test can be either string or function at this point
501+
495502
# ensure that glue statements have only names that are also in the data
496503

497504
# ensure extensions are provided correctly
@@ -502,18 +509,18 @@
502509
if(!testCharacter(x = protocol$extends_note, any.missing = FALSE, min.len = 1)) stop("please provide a short note about what this extension changes.")
503510
}
504511

505-
# turn test string into function
506-
if (is.character(protocol$test)) {
507-
protocol$test <- eval(parse(text = protocol$test))
508-
}
509-
510512
# ensure packages are installed
511513
if(!is.null(protocol$requires)){
512514
for(pkg in protocol$requires){
513515
require(pkg, character.only = TRUE)
514516
}
515517
}
516518

519+
# ensure test is a function for execution
520+
if (is.character(protocol$test)) {
521+
protocol$test <- eval(parse(text = protocol$test))
522+
}
523+
517524
# does the test run with the provided data
518525
testResult <- tryCatch({
519526
exec(protocol$test, !!!protocol$data)
@@ -532,6 +539,8 @@
532539
stop("'test' and 'data' don't result in a valid call.")
533540
}
534541

542+
# keep test as function for bf_map execution
543+
# string conversion only happens in bf_protocol for final storage
535544
return(protocol)
536545

537546
}
@@ -673,11 +682,11 @@ project <- function(title, year = format(Sys.Date(), "%Y"), language = "en",
673682

674683

675684
# Add creators from registry metadata
676-
if (!is.null(registry@metadata$author)) {
677-
authors <- if (inherits(registry@metadata$author, "person")) {
678-
list(registry@metadata$author)
685+
if (!is.null(registry@attribution$author)) {
686+
authors <- if (inherits(registry@attribution$author, "person")) {
687+
list(registry@attribution$author)
679688
} else {
680-
registry@metadata$author
689+
registry@attribution$author
681690
}
682691

683692
output$creators <- map(authors, function(p) {
@@ -729,19 +738,19 @@ project <- function(title, year = format(Sys.Date(), "%Y"), language = "en",
729738
}
730739

731740
# Determine publisher
732-
if (!is.null(registry@metadata$project$publisher)) {
733-
output$publisher <- registry@metadata$project$publisher
734-
} else if (!is.null(registry@metadata$author) &&
735-
!is.null(registry@metadata$author$comment) &&
736-
"affiliation" %in% names(registry@metadata$author$comment)) {
737-
output$publisher <- registry@metadata$author$comment[["affiliation"]]
741+
if (!is.null(registry@attribution$project$publisher)) {
742+
output$publisher <- registry@attribution$project$publisher
743+
} else if (!is.null(registry@attribution$author) &&
744+
!is.null(registry@attribution$author$comment) &&
745+
"affiliation" %in% names(registry@attribution$author$comment)) {
746+
output$publisher <- registry@attribution$author$comment[["affiliation"]]
738747
} else {
739748
output$publisher <- "Individual Researcher"
740749
}
741750

742-
# Add project metadata if available
743-
if (!is.null(registry@metadata$project)) {
744-
proj <- registry@metadata$project
751+
# Add project attribution if available
752+
if (!is.null(registry@attribution$project)) {
753+
proj <- registry@attribution$project
745754

746755
# Add subjects/keywords
747756
if (!is.null(proj$subject)) {
@@ -781,10 +790,10 @@ project <- function(title, year = format(Sys.Date(), "%Y"), language = "en",
781790
}
782791

783792
# Add rights/license information
784-
if (!is.null(registry@metadata$license)) {
785-
rights <- list(rights = registry@metadata$license)
786-
if (registry@metadata$license %in% names(known_licenses)) {
787-
rights$rightsURI <- known_licenses[[registry@metadata$license]]
793+
if (!is.null(registry@attribution$license)) {
794+
rights <- list(rights = registry@attribution$license)
795+
if (registry@attribution$license %in% names(known_licenses)) {
796+
rights$rightsURI <- known_licenses[[registry@attribution$license]]
788797
}
789798
output$rightsList <- list(rights)
790799
}
@@ -793,20 +802,20 @@ project <- function(title, year = format(Sys.Date(), "%Y"), language = "en",
793802
if (registry@width > 0) {
794803
# Create flag summary
795804
flag_summary <- map_chr(registry@flags, function(f) {
796-
pcl <- str_split(str_split(f$provenance$wasGeneratedBy[1], ": ", simplify = TRUE)[2], "_", simplify = TRUE)[1]
805+
pcl <- str_split(f$wasGeneratedBy$useTest, "_", simplify = TRUE)[1]
797806

798807
base_info <- sprintf("Bit %s (%s encoding)",
799-
paste(c(min(f$position), max(f$position)), collapse="-"),
808+
paste(c(min(f$wasGeneratedBy$assignPosition), max(f$wasGeneratedBy$assignPosition)), collapse="-"),
800809
bf_pcl[[pcl]]$encoding_type)
801810

802811
# Handle multiple cases for enumeration
803-
if (length(f$description) > 1) {
804-
case_descriptions <- map_chr(seq_along(f$description), function(i) {
805-
sprintf(" %d: %s", i-1, f$description[i])
812+
if (length(f$comment) > 1) {
813+
case_descriptions <- map_chr(seq_along(f$comment), function(i) {
814+
sprintf(" %d: %s", i-1, f$comment[i])
806815
})
807816
return(sprintf("%s:\n%s", base_info, paste(case_descriptions, collapse="\n")))
808817
} else {
809-
return(sprintf("%s: %s", base_info, f$description))
818+
return(sprintf("%s: %s", base_info, f$comment))
810819
}
811820
})
812821

0 commit comments

Comments
 (0)