Title: | Interacting with BibTeX Databases |
---|---|
Description: | Reading and writing BibTeX files using data frames in R sessions. |
Authors: | Miguel Alvarez [aut, cre] |
Maintainer: | Miguel Alvarez <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.0.10 |
Built: | 2024-10-05 04:42:00 UTC |
Source: | https://github.com/kamapu/biblio |
Coercion 'lib_df' objects.
x |
An object to be coerced. |
## Read installed library Refs <- read_bib(x = file.path(path.package("biblio"), "LuebertPliscoff.bib")) # Convert lib_df to data frame as(Refs[1:5, ], "data.frame") # Convert lib_df to bibentry as(Refs[1:5, ], "bibentry")
## Read installed library Refs <- read_bib(x = file.path(path.package("biblio"), "LuebertPliscoff.bib")) # Convert lib_df to data frame as(Refs[1:5, ], "data.frame") # Convert lib_df to bibentry as(Refs[1:5, ], "bibentry")
Conversion method for lib_df
objects into bibentry
.
bib2bibentry(x, ...) ## S3 method for class 'lib_df' bib2bibentry(x, ...)
bib2bibentry(x, ...) ## S3 method for class 'lib_df' bib2bibentry(x, ...)
x |
A |
... |
Further arguments passed among methods (not yet in use). |
An bibentry
object.
## Read installed electronic library Bib <- read_bib(x = file.path(path.package("biblio"), "LuebertPliscoff.bib")) ## Convert the first five entries bib2bibentry(Bib[1:5, ])
## Read installed electronic library Bib <- read_bib(x = file.path(path.package("biblio"), "LuebertPliscoff.bib")) ## Convert the first five entries bib2bibentry(Bib[1:5, ])
An S3 class for compared data frames. A list containing added, deleted entries on the regarding a key column and cells that are modified.
Report on differences between two versions of the same data frame or electronic library. When used for data frames, you need to indicate the variable containing IDs for each entry, while applied to lib_df objects, the variable 'bibtexkey' will be considered as ID per default.
The output printed in the console will advice about added and deleted entries in 'y' as well as any change in the entries common to both versions.
compare_df(x, y, key, ...) ## S4 method for signature 'data.frame,data.frame,character' compare_df(x, y, key, ...) ## S4 method for signature 'lib_df,lib_df,missing' compare_df(x, y, key, ...)
compare_df(x, y, key, ...) ## S4 method for signature 'data.frame,data.frame,character' compare_df(x, y, key, ...) ## S4 method for signature 'lib_df,lib_df,missing' compare_df(x, y, key, ...)
x |
The (old) reference data frame. |
y |
The updated (new) data frame. |
key |
A character value with the name of the variable used as primary key in the tables. |
... |
Further arguments passed among methods. |
A S3 object of class comp_df, which can be printed in the console by
print()
.
# Partially matching libraries Refs1 <- synopsis[1:10, ] Refs2 <- synopsis[6:15, ] # some modification in second library Refs2[3, "title"] <- "New Title" # compare libraries compare_df(Refs1, Refs2)
# Partially matching libraries Refs1 <- synopsis[1:10, ] Refs2 <- synopsis[6:15, ] # some modification in second library Refs2[3, "title"] <- "New Title" # compare libraries compare_df(Refs1, Refs2)
This function screens a character vector (usually an imported r-markdown
document) for the use of citations by bibtexkeys (@bibtexkey
), retrieving
the detected key with its occurrence in the vector, assuming each element as
a line of the original document.
This function is based on bbt_detect_citations()
from the package
rbbt.
detect_keys(x, ...) ## S3 method for class 'character' detect_keys(x, ...) ## S3 method for class 'rmd_doc' detect_keys(x, ...)
detect_keys(x, ...) ## S3 method for class 'character' detect_keys(x, ...) ## S3 method for class 'rmd_doc' detect_keys(x, ...)
x |
A character vector, a file imported by |
... |
Further arguments passed among methods. In character-method they
are passed to |
A data frame with two columns, bibtexkey
for the found keys and line
with the line number of the occurrence of the key in the document.
## Screen for citations in installed document cited_refs <- detect_keys(file.path(path.package("biblio"), "document.Rmd")) cited_refs
## Screen for citations in installed document cited_refs <- detect_keys(file.path(path.package("biblio"), "document.Rmd")) cited_refs
Retrieving bibliographic entries from Crossref by DOIs.
This function is a wrapper for cr_cn()
.
doi2bib(x, ...)
doi2bib(x, ...)
x |
A character vector including DOI identifiers. |
... |
Further arguments (not yet used). |
The output is an object of class lib_df.
## Retrieve bibliographic entries for two publications dois <- c("10.1111/1748-5967.12330", "10.1016/j.envsci.2019.03.017") bibrefs <- doi2bib(dois) bibrefs
## Retrieve bibliographic entries for two publications dois <- c("10.1111/1748-5967.12330", "10.1016/j.envsci.2019.03.017") bibrefs <- doi2bib(dois) bibrefs
An S3 class for library entries. This class inherits properties from data frames.
A method for a brief overview on the content of a lib_df or a comp_df object.
## S3 method for class 'lib_df' print(x, maxsum = 4, ...) ## S3 method for class 'comp_df' print(x, ...)
## S3 method for class 'lib_df' print(x, maxsum = 4, ...) ## S3 method for class 'comp_df' print(x, ...)
x |
An object of class 'lib_df'. |
maxsum |
An integer value indicating the number of entries to be displayed in the printed output. |
... |
Further arguments passed among methods. |
A print in the console.
Miguel Alvarez
Refs <- read_bib(x = file.path( path.package("biblio"), "LuebertPliscoff.bib" )) print(Refs, maxsum = 10)
Refs <- read_bib(x = file.path( path.package("biblio"), "LuebertPliscoff.bib" )) print(Refs, maxsum = 10)
Reading BibTeX databases and importing into R as a data frame. All the fields will be inserted as character values.
read_bib(x, ...)
read_bib(x, ...)
x |
A single character value with the path to a BibTeX file.
Alternativelly it can be a character vector containing the lines of a
BibTeX library, for instance after using |
... |
Further arguments passed to |
An object of class lib_df.
Refs <- read_bib(x = file.path( path.package("biblio"), "LuebertPliscoff.bib" )) Refs
Refs <- read_bib(x = file.path( path.package("biblio"), "LuebertPliscoff.bib" )) Refs
A fast way to produce a reference list in an r-markdown document from a
lib_df
object.
This function may or may not produce intermediate files (bib and Rmd) and the
result can be assigned to an object for further edition
(see yamlme::update()
).
A html file will be written by write_rmd()
and render_rmd()
in the
working directory and displayed by browseURL()
.
reflist(x, ...) ## S3 method for class 'character' reflist( x, output_file, delete_source = TRUE, title = "Automatic Reference List", output = "html_document", nocite = "'@*'", urlcolor = "blue", encoding = "UTF-8", ... ) ## S3 method for class 'lib_df' reflist(x, filename, delete_source = TRUE, ...)
reflist(x, ...) ## S3 method for class 'character' reflist( x, output_file, delete_source = TRUE, title = "Automatic Reference List", output = "html_document", nocite = "'@*'", urlcolor = "blue", encoding = "UTF-8", ... ) ## S3 method for class 'lib_df' reflist(x, filename, delete_source = TRUE, ...)
x |
A |
... |
Further arguments passed to the yaml header in the intermediate Rmarkdown document. |
output_file |
A character value with the name for the written Rmarkdown file. |
delete_source |
A logical value indicating whether written bib file should be deleted after rendering html or not. |
title , output , nocite , urlcolor
|
Arguments used for the yaml-header in
r-markdown and passed to |
encoding |
A character value indicating the encoding string. It is
passed to |
filename |
A character value with the name for the written Rmd file, without file extension. |
An invisible object of class rmd_doc
. A Rmd file will be written by
write_rmd()
as well.
## Not run: reflist(synopsis) ## End(Not run)
## Not run: reflist(synopsis) ## End(Not run)
Example of an object formatted as lib_df. This library is published with the references of the book Bioclimatic and vegetational synopsis of Chile by Luebert and Pliscoff (2017).
synopsis
synopsis
An object of class lib_df
(inherits from data.frame
) with 1701 rows and 23 columns.
data(synopsis) ## Import from installed bibtex file synopsis <- read_bib(x = file.path( path.package("biblio"), "LuebertPliscoff.bib" ))
data(synopsis) ## Import from installed bibtex file synopsis <- read_bib(x = file.path( path.package("biblio"), "LuebertPliscoff.bib" ))
This function compares two versions of the same data frame and detect changes as additions, deleted entries or updates (modified entries).
A method to compare lib_df objects is also provided as well as a replace method.
update_data(object, revision, key, ...) ## S4 method for signature 'data.frame,data.frame,character' update_data( object, revision, key, add = FALSE, delete = FALSE, update = FALSE, ... ) ## S4 method for signature 'lib_df,lib_df,missing' update_data(object, revision, key, ...) update_data(object, key, ...) <- value ## S4 replacement method for signature 'data.frame,character,data.frame' update_data(object, key, ...) <- value ## S4 replacement method for signature 'lib_df,missing,lib_df' update_data(object, key, ...) <- value
update_data(object, revision, key, ...) ## S4 method for signature 'data.frame,data.frame,character' update_data( object, revision, key, add = FALSE, delete = FALSE, update = FALSE, ... ) ## S4 method for signature 'lib_df,lib_df,missing' update_data(object, revision, key, ...) update_data(object, key, ...) <- value ## S4 replacement method for signature 'data.frame,character,data.frame' update_data(object, key, ...) <- value ## S4 replacement method for signature 'lib_df,missing,lib_df' update_data(object, key, ...) <- value
object |
A data frame or a lib_df object representing the original version. |
revision |
The updated version of 'object' to be compared. |
key |
A character value indicating the column used as identifier. This variable have to be in both versions otherwise this function will retrieve an error. |
... |
Further arguments passed among methods. |
delete , add , update
|
Logical value indicating whether the action
should be carried out. If all are |
value |
The updated version of 'object' in the replace methods. |
Either an invisible output with a print in the console or an updated object of class lib_df.
# Adding an ID to data set iris iris2 <- iris iris2$id <- 1:nrow(iris2) # rows to add using mean values per species iris_mod <- aggregate(cbind( Sepal.Length, Sepal.Width, Petal.Length, Petal.Width ) ~ Species, data = iris2, FUN = mean) iris_mod$id <- (1:nrow(iris_mod)) + nrow(iris2) iris_mod <- do.call(rbind, list(iris2, iris_mod[, colnames(iris2)])) # delete some entries iris_mod <- iris_mod[-c(15, 75, 105, 145), ] # modify entries iris_mod$Petal.Length[c(20, 30)] <- 0 iris_mod$Petal.Width[c(20, 50)] <- 0 # just a comparison update_data(iris2, iris_mod, key = "id") # do update iris2 <- update_data(iris2, iris_mod, key = "id", delete = TRUE, add = TRUE, update = TRUE )
# Adding an ID to data set iris iris2 <- iris iris2$id <- 1:nrow(iris2) # rows to add using mean values per species iris_mod <- aggregate(cbind( Sepal.Length, Sepal.Width, Petal.Length, Petal.Width ) ~ Species, data = iris2, FUN = mean) iris_mod$id <- (1:nrow(iris_mod)) + nrow(iris2) iris_mod <- do.call(rbind, list(iris2, iris_mod[, colnames(iris2)])) # delete some entries iris_mod <- iris_mod[-c(15, 75, 105, 145), ] # modify entries iris_mod$Petal.Length[c(20, 30)] <- 0 iris_mod$Petal.Width[c(20, 50)] <- 0 # just a comparison update_data(iris2, iris_mod, key = "id") # do update iris2 <- update_data(iris2, iris_mod, key = "id", delete = TRUE, add = TRUE, update = TRUE )
BibTeX databases can be created from data frames, interacting with Postgres databases.
write_bib(x, ...) ## S3 method for class 'lib_df' write_bib(x, filename, encoding = "UTF-8", ...)
write_bib(x, ...) ## S3 method for class 'lib_df' write_bib(x, filename, encoding = "UTF-8", ...)
x |
A data frame with bibliographic entries. |
... |
Further arguments passed to |
filename |
A character value with the path and the name of the file to be written. |
encoding |
Character value with the encoding (passed to |
A bibtex file.