Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/seananderson/ramlegacy
R package to download, import, convert, and cache the RAM Legacy Stock Assessment Database
https://github.com/seananderson/ramlegacy
database fisheries r r-package
Last synced: 12 days ago
JSON representation
R package to download, import, convert, and cache the RAM Legacy Stock Assessment Database
- Host: GitHub
- URL: https://github.com/seananderson/ramlegacy
- Owner: seananderson
- Created: 2015-01-22T04:35:21.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2020-05-07T17:23:12.000Z (over 4 years ago)
- Last Synced: 2024-06-11T17:20:32.447Z (5 months ago)
- Topics: database, fisheries, r, r-package
- Language: R
- Size: 18.6 KB
- Stars: 4
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
README
---
output:
md_document:
variant: markdown_github
---```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```# Import the RAM Legacy Stock Assessment Database into R
[![Travis-CI Build Status](https://travis-ci.org/seananderson/ramlegacy.svg?branch=master)](https://travis-ci.org/seananderson/ramlegacy)
**Please use Carl Boettiger and Gupta Kshitiz's ramlegacy package https://github.com/ropensci/ramlegacy instead.**
This package does one thing: it downloads a Microsoft Access copy of the [RAM Legacy Stock Assessment Database](http://ramlegacy.org) and converts it to a local sqlite3 database. This makes it easy to [work with dplyr/dbplyr](https://cran.r-project.org/web/packages/dbplyr/vignettes/dbplyr.html), for example. The `make_ramlegacy()` function also leaves a copy of `.csv` files for each table in the database in the R working directory if you'd prefer to work with those.
**Note that you must have the utility `mdb-tables` installed** and in your path from `mdbtools`. This utility provides tools for extracting Access databases. You can find installation instructions at . If you're on OS X and using homebrew, you can install it with `brew install mdbtools`.
### Example use
```{r knitr-options, cache=FALSE, echo=FALSE}
library("knitr")
opts_chunk$set(cache=TRUE)
```Install the package:
```{r, eval=FALSE}
# install.packages("devtools")
devtools::install_github("seananderson/ramlegacy")
```Cache and convert the database:
```{r}
library("ramlegacy")
make_ramlegacy()
```Work with the data:
```{r}
library("dplyr")
ram <- src_sqlite("ramlegacy.sqlite3")
ram # see the available tables
```Access the `area` table:
```{r}
tbl(ram, "area")
```Join the time series `ts` and `stock` tables on the `stockid` column:
```{r}
ts <- tbl(ram, "timeseries")
stock <- tbl(ram, "stock")
select(stock, stockid, scientificname, commonname, region) %>%
inner_join(ts)
```Note that because you are working with dplyr and a database, you will need to use `dplyr::collect()` once you want to load the data into a local data frame. For example:
```{r}
tbl(ram, "area") %>%
collect()
```For safety, you may want to use `dplyr::collect(n = Inf)` to return all rows of data, not just the minimum default number. In this case it won't make a difference.
```{r}
tbl(ram, "area") %>%
collect(n = Inf)
```