-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
executable file
·139 lines (109 loc) · 4.36 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
---
output:
github_document:
html_preview: false
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
<!-- Use snippet 'render_markdown' for it -->
```{r,echo=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/"
)
```
# biblio
<!-- badges: start -->
[![cran checks](https://badges.cranchecks.info/worst/biblio.svg)](https://cran.r-project.org/web/checks/check_results_biblio.html)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/biblio)](https://cran.r-project.org/package=biblio)
[![r-universe](https://kamapu.r-universe.dev/badges/biblio)](https://kamapu.r-universe.dev/biblio#)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.10984056.svg)](https://doi.org/10.5281/zenodo.10984056)
<br>
[![R-CMD-check](https://github.com/kamapu/biblio/workflows/R-CMD-check/badge.svg)](https://github.com/kamapu/biblio/actions)
[![Codecov test coverage](https://codecov.io/gh/kamapu/biblio/branch/master/graph/badge.svg)](https://codecov.io/gh/kamapu/biblio?branch=master)
[![CRAN_downloads](http://cranlogs.r-pkg.org/badges/biblio)](https://cran.r-project.org/package=biblio)
[![total downloads](http://cranlogs.r-pkg.org/badges/grand-total/biblio)](https://cran.r-project.org/package=biblio)
<!-- badges: end -->
An R-package to manage bibliographic references. This package is focused on
data import-export to a data frame format based on the software
[**JabRef**](http://www.jabref.org/).
## Installing biblio
You can install this package from **GitHub**.
```{r, eval=FALSE}
library(remotes)
install_github("kamapu/biblio")
```
## Reading Bibtex Files
A copy of the references cited in the book of [Luebert & Pliscoff
(2016)](https://doi.org/10.5281/zenodo.60800) is also installed with this
package.
```{r}
library(biblio)
Bib <- read_bib(x = file.path(path.package("biblio"), "LuebertPliscoff.bib"))
Bib
```
## Scanning Cited References in R-Markdown Documents
An example of r-markdown document is also installed to test the
function `detect_keys()`, which is able to recognize the bibtexkeys in use
within an r-markdown document.
```{r}
my_document <- readLines(file.path(path.package("biblio"), "document.Rmd"))
cited_refs <- detect_keys(my_document)
cited_refs
```
Alternatively to the last option, you can use the function `read_rmd()` from
the package [`yamlme`](https://kamapu.github.io/rpkg/yamlme/).
Note that in this case the position of the citation may change because
`detect_keys()` will start counting lines after the yaml-header.
```{r}
library(yamlme)
my_document <- read_rmd(file.path(path.package("biblio"), "document.Rmd"))
cited_refs <- detect_keys(my_document)
cited_refs
```
The output shows the respective bibtexkey by its occurrence in the document
(line number).
With this output it is also possible to do some statistics.
```{r}
stats_refs <- aggregate(line ~ bibtexkey, data = cited_refs, FUN = length)
# Number of citations in text
sum(stats_refs$line)
# Number of cited articles
nrow(stats_refs)
# Respective frequency to know rare citations in text
stats_refs[order(stats_refs$line, decreasing = TRUE), ]
```
## Automatic Reference Lists
The package [`yamlme`](https://kamapu.github.io/rpkg/yamlme/) enables the use
of functions to write R-markdown documents and to render them.
In this context, the function `reflist()` will produce automatically a reference
list.
```{r eval = FALSE}
Bib2 <- subset(x = Bib, subset = as.integer(year) > 2005)
reflist(obj = Bib2, filename = "my_reflist")
```
Note that assigning the output of `reflist()` to a new object and using the
package `yamlme`, you may be able to modify the layout by using the function
`update()`. Remember to set
```{r eval = FALSE}
library(yamlme)
# Subset and assignment
Bib2 <- subset(x = Bib, subset = as.integer(year) > 2005)
my_reflist <- reflist(x = Bib2, filename = "my_reflist", browse_file = FALSE)
# Updating and rendering
my_reflist <- update(
object = my_reflist,
title = "Reference List (PDF version)",
author = "myself",
output = "pdf_document",
body = txt_body(
"\\setlength{\\parindent}{-5mm}",
"\\setlength{\\leftskip}{5mm}",
"\\setlength{\\parskip}{8pt}"
)
)
render_rmd(my_reflist, output_file = "my_reflist")
```
Note that rendering the updated document will also require the written bibtex
file, thus sharing an input bibtexfile or an `lib_df` object within an R-image
may be the most secure way to enable repeatability.