rbhl Introduction

rbhl is an R interface to the Biodiversity Heritage Library.

Installation

Stable version from CRAN

install.packages("rbhl")

Or, development version from GitHub

devtools::install_github("ropensci/rbhl")

Then load library

library("rbhl")

Output formats

You can output various formats using the as parameter, setting to 'json', 'xml', 'list', or 'table'. Note that not all options are available in all functions due to varying returned data objects.

Raw output, in xml format

bhl_authorsearch(name='dimmock', as='xml')

json format

bhl_authorsearch(name='dimmock', as='json')
#> [1] "{\"Status\":\"ok\",\"ErrorMessage\":null,\"Result\":[{\"CreatorID\":1970,\"Name\":\"Dimmock, George,\",\"Role\":null,\"Numeration\":\"\",\"Unit\":\"\",\"Title\":\"\",\"Location\":\"\",\"FullerForm\":\"\",\"Relationship\":null,\"TitleOfWork\":null,\"Dates\":\"1852-\",\"CreatorUrl\":\"http://www.biodiversitylibrary.org/creator/1970\"},{\"CreatorID\":8126,\"Name\":\"Dimmock, George,\",\"Role\":null,\"Numeration\":\"\",\"Unit\":\"\",\"Title\":\"\",\"Location\":\"\",\"FullerForm\":\"\",\"Relationship\":null,\"TitleOfWork\":null,\"Dates\":\"1852-1930\",\"CreatorUrl\":\"http://www.biodiversitylibrary.org/creator/8126\"}]}"

Or get a list

bhl_authorsearch(name='dimmock', as='list')
#> $Status
#> [1] "ok"
#> 
#> $ErrorMessage
#> NULL
#> 
#> $Result
#> $Result[[1]]
#> $Result[[1]]$CreatorID
#> [1] 1970
...

The default option in most functions is to parse to a data.frame

bhl_authorsearch(name='dimmock')
#> <bhl data> [12, 2]
#>   CreatorID             Name Role Numeration Unit Title Location
#> 1      1970 Dimmock, George,   NA                               
#> 2      8126 Dimmock, George,   NA                               
#> Variables not shown: FullerForm (chr), Relationship (lgl), TitleOfWork
#>      (lgl), Dates (chr), CreatorUrl (chr)

Some examples of function calls

Get title metadata

bhl_gettitlemetadata(1726, items = TRUE)
#> $Status
#> [1] "ok"
#> 
#> $ErrorMessage
#> NULL
#> 
#> $Result
#> $Result$TitleID
#> [1] 1726
#> 
...

Book search

bhl_booksearch(title='Selborne', lname='White', volume=2, edition='new', year=1825, collectionid=4, language='eng')
#> <bhl data> [22, 1]
#>   TitleID BibliographicLevel
#> 1   32868                   
#> Variables not shown: FullTitle (chr), ShortTitle (lgl), SortTitle (lgl),
#>      PartNumber (chr), PartName (chr), CallNumber (lgl), Edition (chr),
#>      PublisherPlace (chr), PublisherName (chr), PublicationDate (chr),
#>      PublicationFrequency (lgl), Doi (lgl), TitleUrl (chr), Authors
#>      (list), Subjects (lgl), Identifiers (lgl), Collections (lgl),
#>      Variants (lgl), Items (list), Notes (lgl)

Search titles

bhl_titlesearchsimple('husbandry')
#> <bhl data> [22, 150]
#>    TitleID BibliographicLevel
#> 1    25997     Monograph/Item
#> 2    44403     Monograph/Item
#> 3    27062     Monograph/Item
#> 4    41956     Monograph/Item
#> 5    44462     Monograph/Item
#> 6    28081     Monograph/Item
#> 7    56265     Monograph/Item
#> 8    58205     Monograph/Item
#> 9    51946     Monograph/Item
#> 10   55665     Monograph/Item
#> ..     ...                ...
#> Variables not shown: FullTitle (chr), ShortTitle (chr), SortTitle (chr),
#>      PartNumber (chr), PartName (chr), CallNumber (lgl), Edition (chr),
#>      PublisherPlace (chr), PublisherName (chr), PublicationDate (chr),
#>      PublicationFrequency (chr), Doi (lgl), TitleUrl (lgl), Authors (lgl),
#>      Subjects (lgl), Identifiers (lgl), Collections (lgl), Variants (lgl),
#>      Items (lgl), Notes (lgl)

Get languages

This function gets a list of languages in which materials in BHL have been written.

bhl_getlanguages()
#> <bhl data> [2, 66]
#>    LanguageCode   LanguageName
#> 1           AFR      Afrikaans
#> 2           ARA         Arabic
#> 3           ARC        Aramaic
#> 4           BUL      Bulgarian
#> 5           BUR        Burmese
#> 6           CAR          Carib
#> 7           CAT        Catalan
#> 8           CEL Celtic (Other)
#> 9           CHI        Chinese
#> 10          HRV       Croatian
#> ..          ...            ...

Use case for BHL data

Here, we'll xxx, then plot the data using ggplot2

res <- bhl_booksearch(title = 'Selborne', lname = 'White', volume = 2, edition = 'new', year = 1825, collectionid = 4, language = 'eng')
pages <- getpages(res$data$Items[[1]]$ItemID)

Remove NULL's

pages <- Filter(function(x) !is.null(x), pages)

Cleanup text

pages_clean <- lapply(pages, function(x) gsub("\n", "", x))

Examine pages

pages_clean[10:12]
#> [[1]]
#> [1] "OF SELBORNE. 3, The sternum in this bird seemed to us to  be remarkably short, between which and  the anus lay the crop, or craw, and, imme-  diately behind that, the bowels against the  back-bone. It must be allowed, as this anatomist  observes, that the crop placed just upon the  bowels must, especially when full, be in a  very uneasy situation during the business of  incubation ; yet the test will be, to examine  whether birds that are actually known to  sit for certain are not formed in a similar  manner. This inquiry I proposed to my-  self to make with di fern-owl, or goat-sucker,  as soon as opportunity offered : because if  their formation proves the same, the reason  for incapacity in the cuckoo will be allowed  to have been taken up somewhat hastily. Not long after a fern-owl was procured,  which, from its habit and shape, we sus-  pected might resemble the cuckoo in its  internal construction. Nor were our sus-  picions ill-grounded ; for, upon the dissec-  tion, the crop, or craw, also lay behind the  sternum, immediately on the viscera, be-  . b2 "
#> 
#> [[2]]
#> [1] "4 NATURAL HISTORY tween them and the skin ©f the belly.  It was bulky, and stuffed hard with large  phalcBTKB, moths of several sorts, and their  eggs, which, no doubt, had been forced out  of those insects by the action of swal-  lowing. Now, as it appears that this bird, which  is so well known to practise incubation, is  formed in a similar manner with cuckoos^  Monsieur Herissant's conjecture, that cuc-  koos are incapable of incubation from the  disposition of their intestines, seems to fall  to the ground : and we are still at a loss  for the cause of that strange and singular  peculiarity in the instance of the cuculus  canorus. We found the case to be the same with  the ring-tail hawk, in respect to formation ;  and, as far as I can recollect, with the  swift; and probably it is so with many  more sorts of birds that are not grani-  vorous. I am, &c. "
#> 
#> [[3]]
#> [1] "OF SELBORNE. ,5 Letter xxxl TO THE SAME,  • DEAR SIR; Selborne, April 29, 1776. On August the 4th, 1775, we surprised  a large viper, which seemed very heavy  and bloated, as it lay in the grass basking  in the sun. When we came to cut it up,  we found that the abdomen was crowded  with young, fifteen in number ; the shortest  of which measured full seven inches, and  were about the size of full-grown earth-  worms. This little fry issued into the  world with the true viper spirit about them,  showing great alertness as soon as disen-  gaged from the belly of the dam : they  twisted and riggled about, and set them-  selves up, and gaped very wide when  touched with a stick, showing manifest  tokens of menace and defiance, though as "

With this text data, you can do text mining of the content to answer cool questions you have.