forked from ropensci/codemetar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
390 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
## Methods that guess additional metadata fields based on README badges and realted information | ||
|
||
|
||
guess_published <- function(codemeta){ | ||
|
||
## Currently only considers if published to CRAN | ||
cran_published(codemeta) | ||
} | ||
|
||
cran_published <- function(codemeta){ | ||
if(codemeta$name %in% avail[,"Package"]){ | ||
codemeta$publisher <- | ||
list("@type" = "Organization", | ||
"name" = "CRAN", | ||
"url" = "https://cran.r-project.org") | ||
} | ||
codemeta | ||
|
||
} | ||
|
||
## look for .travis.yml ? GREP .travis badge so we can guess repo name. | ||
guess_ci <- function(codemeta, pkg = "."){ | ||
link <- NULL | ||
if(file.exists("README.md")){ | ||
txt <- readLines("README.md") | ||
badge <- txt[grepl("travis-ci", txt)] | ||
link <- gsub(".*(https://travis-ci.org/\\w+/\\w+).*", "\\1", badge) | ||
} | ||
codemeta$contIntegration <- link | ||
|
||
codemeta | ||
} | ||
|
||
guess_devStatus <- function(codemeta, pkg = "."){ | ||
|
||
link <- NULL | ||
if(file.exists("README.md")){ | ||
txt <- readLines("README.md") | ||
badge <- txt[grepl("Project Status", txt)] | ||
status <- gsub(".*\\[!\\[(Project Status: .*)\\.\\].*", "\\1", badge) | ||
} | ||
codemeta$developmentStatus <- status | ||
codemeta | ||
} | ||
|
||
|
||
## use rorcid / ORCID API to infer ORCID ID from name? | ||
## (Can't use email since only 2% of ORCID users expose email) | ||
## Also can get Affiliation from ORCID search | ||
guess_orcids <- function(codemeta){ | ||
NULL | ||
} | ||
|
||
### Consider: guess_releastNotes() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
## internal method for parsing a list of package dependencies into pkg URLs | ||
|
||
|
||
## cache avail packages | ||
avail <- utils::available.packages(utils::contrib.url("https://cran.rstudio.com", "source")) | ||
|
||
|
||
## FIXME: makes a list of package URLs. Technically we could declare a different type for these, e.g. SoftwareApplication or SoftwareSourceCode | ||
|
||
#' @importFrom utils available.packages contrib.url | ||
parse_depends <- function(deps){ | ||
if(!is.null(deps)) | ||
str <- strsplit(deps, ",\n*")[[1]] | ||
else | ||
str <- NULL | ||
|
||
out <- lapply(str, function(str){ | ||
|
||
## this is vectorized, though we apply it pkg by pkg anyhow | ||
|
||
pkgs <- gsub("\\s*(\\w+)\\s.*", "\\1", str) | ||
pattern <- "\\s*\\w+\\s+\\([><=]+\\s([1-9.\\-]*)\\)*" | ||
versions <- gsub(pattern, "\\1", str) | ||
## We want a NULL, not the full string, if no match is found | ||
nomatch <- !grepl(pattern, str) | ||
versions[nomatch] <- NA | ||
|
||
pkgs <- gsub("\\s+", "", pkgs) | ||
|
||
## Check if pkg is on CRAN | ||
if(all(pkgs %in% avail[,"Package"])) | ||
pkgs <- paste0("https://cran.r-project.org/package=", pkgs) | ||
else{ | ||
message(paste("could not find URL for package", pkgs, "since it is not available on CRAN.")) | ||
} | ||
pkgs | ||
}) | ||
|
||
out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
## internal method, takes R person object and turns to codemeta / json-ld | ||
|
||
## FIXME if @id is available, avoid replicate listing of node? | ||
parse_people <- function(people, codemeta){ | ||
|
||
## listing same person under multiple fields is inelegant? | ||
codemeta$author <- lapply(people[ locate_role(people, "aut") ], person_to_schema) | ||
codemeta$contributor <- lapply(people[ locate_role(people, "ctb") ], person_to_schema) | ||
codemeta$copyrightHolder <- lapply(people[ locate_role(people, "cph") ], person_to_schema) | ||
codemeta$maintainer <- person_to_schema(people[ locate_role(people, "cre") ]) | ||
codemeta | ||
} | ||
|
||
|
||
locate_role <- function(people, role = "aut"){ | ||
vapply(people, function(p) any(grepl(role, p$role)), logical(1)) | ||
} | ||
|
||
person_to_schema <- function(p){ | ||
|
||
## Store ORCID id in comment? | ||
id <- NULL | ||
if(!is.null(p$comment)){ | ||
if(grepl("orcid", p$comment)){ | ||
id <- p$comment | ||
} | ||
} | ||
|
||
## assume type is Organization if family name is null | ||
if(is.null(p$family)) | ||
type <- "Organization" | ||
else | ||
type <- "Person" | ||
list("@id" = id, | ||
"@type" = type, | ||
givenName = p$given, | ||
familyName = p$family, | ||
email = p$email) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.