prisonbrief
prisonbrief: An R package that returns tidy data from the World Prison Brief website - Published in JOSS (2018)
Science Score: 93.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 7 DOI reference(s) in README and JOSS metadata -
✓Academic publication links
Links to: joss.theoj.org, zenodo.org -
○Committers with academic emails
-
○Institutional organization owner
-
✓JOSS paper metadata
Published in Journal of Open Source Software
Keywords
data
prison
rstats
world-prison-brief
Last synced: 4 months ago
·
JSON representation
Repository
An R package that returns tidy data from the World Prison Brief website.
Basic Info
- Host: GitHub
- Owner: danilofreire
- License: other
- Language: R
- Default Branch: master
- Homepage: http://danilofreire.github.io/prisonbrief
- Size: 485 KB
Statistics
- Stars: 17
- Watchers: 2
- Forks: 0
- Open Issues: 1
- Releases: 2
Topics
data
prison
rstats
world-prison-brief
Created over 8 years ago
· Last pushed almost 5 years ago
Metadata Files
Readme
Changelog
Contributing
License
README.Rmd
---
output: github_document
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
[](https://doi.org/10.21105/joss.00361) [](https://doi.org/10.5281/zenodo.1165514) [](https://cran.r-project.org/package=prisonbrief) [](https://travis-ci.org/danilofreire/prisonbrief)  [](https://CRAN.R-project.org/package=prisonbrief)
# prisonbrief: An R package that returns tidy data from the World Prison Brief website
The goal of `prisonbrief` is to download, clean and return data from the [World Prison Brief website](http://www.prisonstudies.org/). The World Prison Brief is an online database compiled by the [Institute for Criminal Policy Research](http://www.icpr.org.uk/) with information on prison systems around the world. Data currently cover 223 jurisdictions and have been collected from public sources. The `prisonbrief` package provides easy-to-use functions to convert WPB data into a format convenient for statistical analysis.
## Installation
The stable version of `prisonbrief` is available on [CRAN](https://cran.r-project.org/package=prisonbrief). To install it, just type:
```{r cran, eval = FALSE}
install.packages("prisonbrief")
```
You can install the most recent development version of `prisonbrief` using the `remotes` package. First, you need to install the `remotes` package with the following code:
```{r remotes-installation, eval = FALSE}
if(!require(remotes)) install.packages("remotes")
```
Then you can install `prisonbrief` from [its GitHub repository](https://github.com/danilofreire/prisonbrief):
```{r gh-installation, eval = FALSE}
remotes::install_github("danilofreire/prisonbrief")
```
If you are using Linux, you may need to type the following command before installing `prisonbrief`:
```{bash linux-dependency, eval = FALSE}
sudo apt-get install libudunits2-dev
```
`prisonbrief` relies on some spatial-data packages in order to return data as simple features dataframes. You may need to install packages such as `rgeos` if you do not already have them installed.
## Usage
`prisonbrief` is quite simple to use. The package contains only three functions, all of them starting with `wpb`, a mnemonic for World Prison Brief.
The first is a convenience function named `wpb_list()`. It prints a list of available countries to the console.
```{r wpb-list}
library(prisonbrief)
wpb_list()
```
The second function is `wpb_table()`. This function returns a series of variables about the prison systems of the world, of a particular region, or of a specific country. For instance, the code below downloads prison data for Africa:
```{r africa}
africa <- wpb_table(region = "Africa")
names(africa)
```
The region choices are "Africa", "Asia", "Caribbean", "Central America", "Europe", "Middle East", "North America", "Oceania", "South America" and "All".
`wpb_table()` also provides geometric shapes for maps. For instance, you can download and plot the prison population rate in South America with only a few lines of code:
```{r ggpplot-map, eval = FALSE}
south_america <- wpb_table(region = "South America")
library(ggplot2)
ggplot(south_america, aes(fill = prison_population_rate)) +
geom_sf() +
scale_fill_distiller(palette = "YlOrRd", trans = "reverse") +
theme_minimal()
```

The function can also be used to retrieve data for a single country. The data returned are parsed from the single country tables, however, and are not ready for quantitative analysis without further cleaning (removing parentheses etc.). Since some of this information may be relevant, we have chosen to leave it in. Data from regions instead of a single country are fully prepared for automated analysis.
Finally, we have added the `wpb_series()` function to the package. The function downloads and tidies the tables describing the trends in the prison population total and the prison population rate for every jurisdiction included in the project. Below is an example taken from [Germany's country profile](http://www.prisonstudies.org/country/germany):

You can retrieve the same information with the following code:
```{r germany}
germany <- wpb_series(country = "Germany")
germany
```
`wpb_series()` can also be combined with `wpb_list()` to make interesting time series graphs. The code below downloads data for all countries then plots the prison population rate for Brazil, Germany, Russia and the United States:
```{r for-loop, warning = FALSE, error = FALSE, eval = FALSE}
library(dplyr)
x <- list()
countries <- wpb_list()
for(i in 1:nrow(countries)){
y <- try(wpb_series(country = countries$country_url[i]), silent = FALSE)
if(class(y) != 'try-error'){
x[[i]] <- y
} else{
next
}
}
X <- data.table::rbindlist(x, fill = TRUE) %>%
dplyr::full_join(countries, by = c("Country" = "country_url"))
X %>% dplyr::filter(country_name %in% c("Brazil",
"Germany",
"Russian Federation",
"United States of America")) %>%
ggplot(aes(x = Year, y = `Prison population rate`,
group = country_name, colour = country_name)) +
geom_line() +
theme_minimal()
```

## Contributions
`prisonbrief` was written by [Danilo Freire](http://danilofreire.github.io/) and [Robert Myles McDonnell](https://www.robertmylesmcdonnell.com/). Feedback and comments are most welcome. If you have any suggestions on how to improve this package feel free to [open an issue on GitHub](https://github.com/danilofreire/prisonbrief/issues).
## Citation
You can cite the `prisonbrief` package with:
```{r citation}
citation("prisonbrief")
```
Please also cite the source as [World Prison Brief, Institute for Criminal Policy Research](http://www.prisonstudies.org/about-us).
Owner
- Name: Danilo Freire
- Login: danilofreire
- Kind: user
- Repositories: 87
- Profile: https://github.com/danilofreire
JOSS Publication
prisonbrief: An R package that returns tidy data from the World Prison Brief website
Published
February 05, 2018
Volume 3, Issue 22, Page 361
Authors
Robert Myles McDonnell
Avanade
Avanade
Tags
data prison rstats world prison dataGitHub Events
Total
Last Year
Committers
Last synced: 5 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Danilo Freire | d****e@g****m | 53 |
| Robert Myles McDonnell | m****5@g****m | 21 |
| Robert Myles McDonnell | r****l@g****m | 5 |
Issues and Pull Requests
Last synced: 4 months ago
All Time
- Total issues: 5
- Total pull requests: 1
- Average time to close issues: 3 months
- Average time to close pull requests: 16 days
- Total issue authors: 3
- Total pull request authors: 1
- Average comments per issue: 1.6
- Average comments per pull request: 0.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- RobertMyles (3)
- danilofreire (1)
- AmberCXX (1)
Pull Request Authors
- RobertMyles (1)
Top Labels
Issue Labels
enhancement (1)
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- cran 198 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 2
- Total maintainers: 1
cran.r-project.org: prisonbrief
Downloads and Parses World Prison Brief Data
- Homepage: https://danilofreire.github.io/prisonbrief/
- Documentation: http://cran.r-project.org/web/packages/prisonbrief/prisonbrief.pdf
- License: MIT + file LICENSE
-
Latest release: 0.1.2
published almost 5 years ago
Rankings
Stargazers count: 13.3%
Forks count: 28.8%
Dependent packages count: 29.8%
Dependent repos count: 35.5%
Average: 35.8%
Downloads: 71.8%
Maintainers (1)
Last synced:
4 months ago
Dependencies
DESCRIPTION
cran
- R >= 3.0 depends
- dplyr >= 0.5.0 imports
- httr >= 1.2.1 imports
- magrittr >= 1.5 imports
- passport >= 0.1.1 imports
- rnaturalearth >= 0.1.0 imports
- rnaturalearthdata >= 0.1.0 imports
- rvest >= 0.3.2 imports
- sf >= 0.6.0 imports
- stringr >= 1.2.0 imports
- tibble >= 1.3.3 imports
- tidyr >= 0.6.3 imports
- xml2 >= 1.1.1 imports
- testthat * suggests
