Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • b7f770a
  • /
  • tests
  • /
  • test.R
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:f45fb6c42345a23fd48ce4f8188dca55213e009b
directory badge
swh:1:dir:33078853593f8ca1edad0c206807fa344ec13ebb

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
test.R

## call rmarkdown on all .Rmd files
#f <- list.files(recursive = TRUE)
#lapply(f[grepl(".Rmd$", f)], rmarkdown::render)


library("jsonld")
library("jsonlite")
library("magrittr")
library("testthat")

#context <- "codemeta.jsonld"
context <- "https://raw.githubusercontent.com/codemeta/codemeta/master/codemeta.jsonld"



## Round trip expansion and compaction should give us the same thing
validate <- function(example){
  jsonld_expand(example) %>%
  jsonld_compact(context) %>% 
  writeLines("test.json")
  
  ## Same properties in each
  A <- read_json(example) 
  B <- read_json("test.json") 

  unlink("test.json")
  
  ## drop context, we don't care if one is literal and one the URL of context, what matters is content
  A$`@context` <- NULL 
  B$`@context`  <- NULL 
  
  ## sort since order does not matter to JSON
  
  ## Same number of properties as we started with?
  same_number <- identical(
    A %>% unlist() %>% length(),
    B %>% unlist() %>% length())
  
  ## Did any properties fail to compact back?
  compaction_fail <-
  B %>% unlist() %>% names() %>% grepl(pattern = ":") %>% any()
  
  same_number && !compaction_fail
  
}

expect_true(validate("../examples/codemeta.json"))
expect_true(validate("../examples/schema-org-codemeta.json"))

expect_false(validate("../examples/example-codemeta-invalid.json"))

## author isn't a list type, so doesn't compact
expect_false(validate("../examples/example-code-jsonld.json"))             


## Verify we have subset the schema.org correctly, e.g we have the same behavior as a context of [codemeta.json, http://schema.org]

             

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API