seasl

library("knitr")
hook_output <- knitr::knit_hooks$get("output")
knitr::knit_hooks$set(output = function(x, options) {
   lines <- options$output.lines
   if (is.null(lines)) {
     return(hook_output(x, options))  # pass to default hook
   }
   x <- unlist(strsplit(x, "\n"))
   more <- "..."
   if (length(lines)==1) {        # first n lines
     if (length(x) > lines) {
       # truncate the output, but add ....
       x <- c(head(x, lines), more)
     }
   } else {
     x <- c(if (abs(lines[1])>1) more else NULL,
            x[lines],
            if (length(x)>lines[abs(length(lines))]) more else NULL
           )
   }
   # paste these lines together
   x <- paste(c(x, ""), collapse = "\n")
   hook_output(x, options)
 })

knitr::opts_chunk$set(
  comment = "#>",
  collapse = TRUE,
  warning = FALSE,
  message = FALSE
)

Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. R build status rstudio mirror downloads cran version

seasl is an R client for exploring CSL styles.

This package is inspired by the Ruby gem csl: https://github.com/inukshuk/csl-ruby

The Citation Style Language 1.0.1 specification: http://docs.citationstyles.org/en/1.0.1/specification.html

Package API:

# cat(paste(" -", paste(sort(getNamespaceExports("seasl")), collapse = "\n - ")))
cat(paste(" -", paste(sprintf("`%s`", getNamespaceExports("seasl")), collapse = "\n - ")))

Install

install.packages("seasl")

or

remotes::install_github("ropensci/seasl")
library("seasl")

Download styles and locales

First, you may want to download style and locale files. csl_fetch_styles() and csl_fetch_locales() download the files to your machine. See ?csl_cache for caching information, including how to change the cache location.

Styles retrieved from the Github repo at https://github.com/citation-style-language/styles-distribution

csl_fetch_styles()
#>
#> Done! Files put in /Users/sckott/Library/Caches/R/seasl/styles

Locales retrieved from the Github repo at https://github.com/citation-style-language/locales

csl_fetch_locales()
#>
#> Done! Files put in /Users/sckott/Library/Caches/R/seasl/locales

File paths to CSL styles and locales

calling csl_styles without inputs gives all styles, with separate lists for dependent and independent styles

csl_styles()

calling csl_styles with an input gives the path to that style, if found

csl_styles("apa")
csl_styles("archeologie-medievale")

Same patterns go for locales (note that there are far fewer locales than styles)

# just locale names
csl_locales()
# when locale given, you get the full path
csl_locales("fr-FR")

Alternatively, you can try to find a style by using csl_style_find()

# single match
csl_style_find(x = "American Journal of Epidemiology")
# many matches
csl_style_find(x = "American Journal")

Load CSL style from a URL

jps <- csl_style_load('http://www.zotero.org/styles/american-journal-of-political-science')

Query style information

jps$info
jps$info$title
jps$macros
jps$citation
jps$bibliography

Get raw XML

csl_style_xml('http://www.zotero.org/styles/american-journal-of-political-science')

Meta

ropensci_footer



ropenscilabs/seasl documentation built on Sept. 12, 2022, 4:11 p.m.