knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
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 and converts it to a local sqlite3 database. This makes it easy to work with dplyr/dbplyr, 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 http://mdbtools.sourceforge.net. If you're on OS X and using homebrew, you can install it with brew install mdbtools
.
library("knitr") opts_chunk$set(cache=TRUE)
Install the package:
# install.packages("devtools") devtools::install_github("seananderson/ramlegacy")
Cache and convert the database:
library("ramlegacy") make_ramlegacy()
Work with the data:
library("dplyr") ram <- src_sqlite("ramlegacy.sqlite3") ram # see the available tables
Access the area
table:
tbl(ram, "area")
Join the time series ts
and stock
tables on the stockid
column:
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:
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.
tbl(ram, "area") %>% collect(n = Inf)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.