Skip to contents

Validate a CITATION.cff file or a cff object using the corresponding validation schema.

Usage

cff_validate(x = "CITATION.cff", verbose = TRUE)

Arguments

x

This is expected to be either a full cff object created with cff_create() or the path to a CITATION.cff file to be validated. In the case of a *cff file it would read with cff_read_cff_citation().

verbose

Logical TRUE/FALSE. On TRUE the function would display informative messages.

Value

A message indicating the result of the validation and an invisible value TRUE/FALSE. On error, the results would have an attribute "errors" containing the error summary (see Examples and attr()).

See also

Guide to Citation File Format schema version 1.2.0.

jsonvalidate::json_validate(), that is the function that performs the validation.

Other core functions of cffr: cff(), cff_create(), cff_modify()

Examples

# \donttest{
# Full .cff example
cff_validate(system.file("examples/CITATION_complete.cff", package = "cffr"))
#> ══ Validating cff ══════════════════════════════════════════════════════════════
#>  Congratulations! /usr/local/lib/R/site-library/cffr/examples/CITATION_complete.cff is valid

# Validate a cffr object
cffr <- cff_create("jsonlite")
class(cffr)
#> [1] "cff"
cff_validate(cffr)
#> ══ Validating cff ══════════════════════════════════════════════════════════════
#>  Congratulations! This <cff> is valid
# }

# .cff with errors
err_f <- system.file("examples/CITATION_error.cff", package = "cffr")
# Can manipulate the errors as data frame
res <- try(cff_validate(err_f))
#> ══ Validating cff ══════════════════════════════════════════════════════════════
#>  Oops! /usr/local/lib/R/site-library/cffr/examples/CITATION_error.cff has the following errors:
#> * cff: has additional properties
#> * cff.authors.0: no schemas match
#> * cff.doi: referenced schema does not match
#> * cff.keywords.0: is the wrong type
#> * cff.license: referenced schema does not match
#> * cff.url: referenced schema does not match

isTRUE(res)
#> [1] FALSE
isFALSE(res)
#> [1] TRUE

attr(res, "errors")
#>            field                          message
#> 1            cff        has additional properties
#> 2  cff.authors.0                 no schemas match
#> 3        cff.doi referenced schema does not match
#> 4 cff.keywords.0                is the wrong type
#> 5    cff.license referenced schema does not match
#> 6        cff.url referenced schema does not match

# If a CITATION file (note that is not .cff) it throws an error
try(cff_validate(system.file("CITATION", package = "cffr")))
#> Error in abort_if_not_cff(x) : `x` is not a '*.cff' file.