This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
178 lines (134 loc) · 4.5 KB
/
README.Rmd
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
seasl
=====
```{r echo=FALSE}
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.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
![R build status](https://github.com/ropensci/seasl/workflows/R-CMD-check/badge.svg)
[![rstudio mirror downloads](https://cranlogs.r-pkg.org/badges/seasl?color=C9A115)](https://github.com/metacran/cranlogs.app)
[![cran version](https://www.r-pkg.org/badges/version/seasl)](https://cran.r-project.org/package=seasl)
<!-- [![Build Status](https://travis-ci.org/ropensci/seasl.svg?branch=master)](https://travis-ci.org/ropensci/seasl) -->
`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:
```{r echo=FALSE, comment=NA, results='asis'}
# cat(paste(" -", paste(sort(getNamespaceExports("seasl")), collapse = "\n - ")))
cat(paste(" -", paste(sprintf("`%s`", getNamespaceExports("seasl")), collapse = "\n - ")))
```
## Install
```{r eval=FALSE}
install.packages("seasl")
```
or
```{r eval=FALSE}
remotes::install_github("ropensci/seasl")
```
```{r}
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
```{r eval=FALSE}
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
```{r eval=FALSE}
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
```{r output.lines = 1:10}
csl_styles()
```
calling `csl_styles` with an input gives the path to that style, if found
```{r}
csl_styles("apa")
csl_styles("archeologie-medievale")
```
Same patterns go for locales (note that there are far fewer locales than styles)
```{r}
# just locale names
csl_locales()
```
```{r}
# 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()`
```{r}
# single match
csl_style_find(x = "American Journal of Epidemiology")
```
```{r output.lines = 1:10}
# many matches
csl_style_find(x = "American Journal")
```
## Load CSL style from a URL
```{r}
jps <- csl_style_load('http://www.zotero.org/styles/american-journal-of-political-science')
```
## Query style information
```{r output.lines = 1:10}
jps$info
```
```{r}
jps$info$title
```
```{r output.lines = 1:10}
jps$macros
```
```{r output.lines = 1:10}
jps$citation
```
```{r output.lines = 1:10}
jps$bibliography
```
## Get raw XML
```{r output.lines=1:10}
csl_style_xml('http://www.zotero.org/styles/american-journal-of-political-science')
```
## Meta
* Please [report any issues or bugs](https://github.com/ropensci/seasl/issues).
* License: MIT
* Citation: execute `citation(package = 'seasl')`
* Please note that this project is released with a [Contributor Code of Conduct][coc]. By participating in this project you agree to abide by its terms.
[![ropensci_footer](https://ropensci.org/public_images/github_footer.png)](https://ropensci.org)
[coc]: https://github.com/ropensci/seasl/blob/master/CODE_OF_CONDUCT.md