Description Details Public fields Methods Note Examples
handlr client, read and write to and from all citation formats
The various inputs to the x parameter are handled in different
ways:
file: contents read from file, we grab file extension, and we guess format based on combination of contents and file extension because file extensions may belie what's in the file
string: string read in, and we guess format based on contents of the string
DOI: we request citeproc-json format from the Crossref API
DOI url: we request citeproc-json format from the Crossref API
path(character) non-empty if file path passed to initialize
string(character) non-empty if string (non-file) passed to initialize
parsedafter read() is run, the parsed content
file(logical) TRUE if a file passed to initialize, else FALSE
ext(character) the file extension
format_guessed(character) the guessed file format
doi(character) the DOI, if any found
print()print method for HandlrClient objects
HandlrClient$print(x, ...)
xself
...ignored
new()Create a new HandlrClient object
HandlrClient$new(x, format = NULL, ...)
x(character) a file path (the file must exist), a string containing contents of the citation, a DOI, or a DOI as a URL. See Details.
format(character) one of citeproc, ris, bibtex, codemeta, cff,
or NULL. If NULL, we attempt to guess the format, and error if we
can not guess
...curl options passed on to crul::verb-GET
A new HandlrClient object
read()read input
HandlrClient$read(format = NULL, ...)
format(character) one of citeproc, ris, bibtex, codemeta, cff,
or NULL. If NULL, we attempt to guess the format, and error if we
can not guess
...further args to the writer fxn, if any
write()write to std out or file
HandlrClient$write(format, file = NULL, ...)
format(character) one of citeproc, ris, bibtex, schema_org, rdfxml, codemeta, or cff
filea file path, if NULL to stdout. for format=ris,
number of files must equal number of ris citations
...further args to the writer fxn, if any
as_df()convert data to a data.frame using handl_to_df()
HandlrClient$as_df()
a data.frame
clone()The objects of this class are cloneable with this method.
HandlrClient$clone(deep = FALSE)
deepWhether to make a deep clone.
If $parsed is NULL then it's likely $read() has not
been run - in which case we attempt to run $read() to
populate $parsed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | # read() can be run with format specified or not
# if format not given, we attempt to guess the format and then read
z <- system.file('extdata/citeproc.json', package = "handlr")
(x <- HandlrClient$new(x = z))
x$read()
x$read("citeproc")
x$parsed
# you can run read() then write()
# or just run write(), and read() will be run for you if possible
z <- system.file('extdata/citeproc.json', package = "handlr")
(x <- HandlrClient$new(x = z))
cat(x$write("ris"))
# read from a DOI as a url
if (interactive()) {
(x <- HandlrClient$new('https://doi.org/10.7554/elife.01567'))
x$parsed
x$read()
x$parsed
x$write('bibtex')
}
# read from a DOI
if (interactive()) {
(x <- HandlrClient$new('10.7554/elife.01567'))
x$parsed
x$read()
x$write('bibtex')
}
# read in citeproc, write out bibtex
z <- system.file('extdata/citeproc.json', package = "handlr")
(x <- HandlrClient$new(x = z))
x$path
x$ext
x$read("citeproc")
x$parsed
x$write("bibtex")
f <- tempfile(fileext = ".bib")
x$write("bibtex", file = f)
readLines(f)
unlink(f)
# read in ris, write out ris
z <- system.file('extdata/peerj.ris', package = "handlr")
(x <- HandlrClient$new(x = z))
x$path
x$format_guessed
x$read("ris")
x$parsed
x$write("ris")
cat(x$write("ris"))
# read in bibtex, write out ris
(z <- system.file('extdata/bibtex.bib', package = "handlr"))
(x <- HandlrClient$new(x = z))
x$path
x$format_guessed
if (requireNamespace("bibtex", quietly = TRUE)) {
x$read("bibtex")
x$parsed
x$write("ris")
cat(x$write("ris"))
}
# read in bibtex, write out RDF XML
if (requireNamespace("bibtex", quietly = TRUE) && interactive()) {
(z <- system.file('extdata/bibtex.bib', package = "handlr"))
(x <- HandlrClient$new(x = z))
x$path
x$format_guessed
x$read("bibtex")
x$parsed
x$write("rdfxml")
cat(x$write("rdfxml"))
}
# codemeta
(z <- system.file('extdata/codemeta.json', package = "handlr"))
(x <- HandlrClient$new(x = z))
x$path
x$format_guessed
x$read("codemeta")
x$parsed
x$write("codemeta")
# cff: Citation File Format
(z <- system.file('extdata/citation.cff', package = "handlr"))
(x <- HandlrClient$new(x = z))
x$path
x$format_guessed
x$read("cff")
x$parsed
x$write("codemeta")
# > 1 citation
z <- system.file('extdata/citeproc-many.json', package = "handlr")
(x <- HandlrClient$new(x = z))
x$parsed
x$read()
x$parsed
## schmea org
x$write("schema_org")
## bibtex
x$write("bibtex")
## bibtex to file
f <- tempfile(fileext=".bib")
x$write("bibtex", f)
readLines(f)
unlink(f)
## to RIS
x$write("ris")
### only one per file, so not combined
files <- replicate(2, tempfile(fileext=".ris"))
x$write("ris", files)
lapply(files, readLines)
# handle strings instead of files
z <- system.file('extdata/citeproc-crossref.json', package = "handlr")
(x <- HandlrClient$new(x = readLines(z)))
x$read("citeproc")
x$parsed
cat(x$write("bibtex"), sep = "\n")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.