Skip to content

Commit

Permalink
Fix “NSF award in db” check
Browse files Browse the repository at this point in the history
  • Loading branch information
gothub committed Dec 4, 2018
1 parent b58cba2 commit fa07176
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/resources/checks/nsf.award.number.in.db.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<environment>rscript</environment>
<code><![CDATA[
library(httr)
library(stringr)
NSFawardLength <- 7
if (is.null(awards)) {
Expand All @@ -19,14 +20,16 @@ if (is.null(awards)) {
} else {
# Clean up each award string so we can pass it to the HTTP API
awards <- trimws(gsub("nsf award", "", tolower(awards)))
# Extract the integer funding numbers from any other character left in the 'funding' element.
awards <- str_extract(awards, "\\d+")
# Make sure that all award numbers are the correct number of characters
# The number may have been stripped of leading zeros, so add them back
# in if necessary.
awardFormat <- paste0("%0", NSFawardLength, "d")
awards <- lapply(awards, function(x) {
award <- x
if(nchar(x) < NSFawardLength) {
award <- sprintf(awardFormat, as.integer(x))
award <- sprintf(awardFormat, as.integer(x))
}
as.character(award)
})
Expand Down Expand Up @@ -62,6 +65,6 @@ if (is.null(awards)) {
]]></code>
<selector>
<name>awards</name>
<xpath>/eml/dataset/project/funding//para | /eml/dataset/project/funding</xpath>
<xpath>/*[local-name() = 'eml']/dataset/project/funding//text()[normalize-space()]</xpath>
</selector>
</mdq:check>

0 comments on commit fa07176

Please sign in to comment.