• Stars
    star
    100
  • Rank 321,955 (Top 7 %)
  • Language
    R
  • Created over 12 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

R interface to the fishbase.org database

rfishbase

R-CMD-check Coverage status Onboarding CRAN status Downloads

Welcome to rfishbase 4. This is the fourth rewrite of the original rfishbase package described in Boettiger et al. (2012).

  • rfishbase 1.0 relied on parsing of XML pages served directly from Fishbase.org.
  • rfishbase 2.0 relied on calls to a ruby-based API, fishbaseapi, that provided access to SQL snapshots of about 20 of the more popular tables in FishBase or SeaLifeBase.
  • rfishbase 3.0 side-stepped the API by making queries which directly downloaded compressed csv tables from a static web host. This substantially improved performance a reliability, particularly for large queries. The release largely remained backwards compatible with 2.0, and added more tables.
  • rfishbase 4.0 extends the static model and interface. Static tables are distributed in parquet and accessed through a provenance-based identifier. While old functions are retained, a new interface is introduced to provide easy access to all fishbase tables.

We welcome any feedback, issues or questions that users may encounter through our issues tracker on GitHub: https://github.com/ropensci/rfishbase/issues

Installation

remotes::install_github("ropensci/rfishbase")
library("rfishbase")
library("dplyr") # convenient but not required

Getting started

Generic table interface

All fishbase tables can be accessed by name using the fb_tbl() function:

fb_tbl("ecosystem")
# A tibble: 157,870 × 18
   autoctr E_CODE Ecosy…¹ Specc…² Stock…³ Status Curre…⁴ Abund…⁵ LifeS…⁶ Remarks
     <int>  <int>   <int>   <int>   <int> <chr>  <chr>   <chr>   <chr>   <chr>  
 1       1      1   50628     549     565 native Present <NA>    adults  <NA>   
 2       2      1     189     552     568 native Present <NA>    adults  <NA>   
 3       3      1     189     554     570 native Present <NA>    adults  <NA>   
 4       4      1   79732     873     889 native Present <NA>    adults  <NA>   
 5       5      1    5217     948     964 native Present <NA>    adults  <NA>   
 6       7      1   39852     956     972 native Present <NA>    adults  <NA>   
 7       8      1   39852     957     973 native Present <NA>    adults  <NA>   
 8       9      1   39852     958     974 native Present <NA>    adults  <NA>   
 9      10      1     188    1526    1719 native Present <NA>    adults  <NA>   
10      11      1     188    1626    1819 native Present <NA>    adults  <NA>   
# … with 157,860 more rows, 8 more variables: Entered <int>,
#   Dateentered <dttm>, Modified <int>, Datemodified <dttm>, Expert <int>,
#   Datechecked <dttm>, WebURL <chr>, TS <dttm>, and abbreviated variable names
#   ¹​EcosystemRefno, ²​Speccode, ³​Stockcode, ⁴​CurrentPresence, ⁵​Abundance,
#   ⁶​LifeStage

You can see all the tables using fb_tables() to see a list of all the table names (specify sealifebase if desired). Careful, there are a lot of them! The fishbase databases have grown a lot in the decades, and were not intended to be used directly by most end-users, so you may have considerable work to determine what’s what. Keep in mind that many variables can be estimated in different ways (e.g. trophic level), and thus may report different values in different tables. Also note that species is name (or SpecCode) is not always the primary key for a table – many tables are specific to stocks or even individual samples, and some tables are reference lists that are not species focused at all, but meant to be joined to other tables (faoareas, etc). Compare tables against what you see on fishbase.org, or ask on our issues forum for advice!

fish <- c("Oreochromis niloticus", "Salmo trutta")

fb_tbl("species") %>% 
  mutate(sci_name = paste(Genus, Species)) %>%
  filter(sci_name %in% fish) %>% 
  select(sci_name, FBname, Length)
# A tibble: 2 × 3
  sci_name              FBname       Length
  <chr>                 <chr>         <dbl>
1 Oreochromis niloticus Nile tilapia     60
2 Salmo trutta          Sea trout       140

SeaLifeBase

SeaLifeBase.org is maintained by the same organization and largely parallels the database structure of Fishbase. As such, almost all rfishbase functions can instead be instructed to address the

fb_tbl("species", "sealifebase")
# A tibble: 103,169 × 109
   SpecCode Genus  Species Author Speci…¹ FBname FamCode Subfa…² GenCode TaxIs…³
      <int> <chr>  <chr>   <chr>    <int> <chr>    <int> <chr>     <int>   <int>
 1    10217 Abyss… cidaris Poore…    3113 <NA>       512 <NA>       9280       0
 2    10218 Abyss… panope  Poore…    3113 <NA>       512 <NA>       9280       0
 3    90399 Abyss… averin… Kussa…    3113 <NA>       502 <NA>      17490       0
 4    52610 Abyss… millari Monni…    2585 <NA>       978 <NA>       9281       0
 5    52611 Abyss… wyvill… Herdm…    2892 <NA>       978 <NA>       9281       0
 6   138684 Abyss… planus  (Slad…   81020 <NA>      1615 <NA>      24229       0
 7    90400 Abyss… acutil… Doti …    3113 <NA>       587 <NA>       9282       0
 8    10219 Abyss… argent… Menzi…    3113 <NA>       587 <NA>       9282       0
 9    10220 Abyss… bathya… Just,…    3113 <NA>       587 <NA>       9282       0
10    10221 Abyss… dentif… Menzi…    3113 <NA>       587 <NA>       9282       0
# … with 103,159 more rows, 99 more variables: Remark <chr>,
#   PicPreferredName <chr>, PicPreferredNameM <chr>, PicPreferredNameF <chr>,
#   PicPreferredNameJ <chr>, Source <chr>, AuthorRef <int>, SubGenCode <int>,
#   Fresh <int>, Brack <int>, Saltwater <int>, Land <int>, BodyShapeI <chr>,
#   DemersPelag <chr>, AnaCat <chr>, MigratRef <int>, DepthRangeShallow <int>,
#   DepthRangeDeep <int>, DepthRangeRef <int>, DepthRangeComShallow <int>,
#   DepthRangeComDeep <int>, DepthComRef <int>, LongevityWild <dbl>, …

Versions and importing all tables

By default, tables are downloaded the first time they are used. rfishbase defaults to download the latest available snapshot; be aware that the most recent snapshot may be months behind the latest data on fishbase.org. Check available releases:

available_releases()
[1] "23.01" "21.06" "19.04"

Low-memory environments

If you have very limited RAM (e.g. <= 1 GB available) it may be helpful to use fishbase tables in remote form by setting collect = FALSE. This allows the tables to remain on disk, while the user is still able to use almost all dplyr functions (see the dbplyr vignette). Once the table is appropriately subset, the user will need to call dplyr::collect() to use generic non-dplyr functions, such as plotting commands.

fb_tbl("occurrence")
# A tibble: 1,097,303 × 106
   catnum2 OccurrenceR…¹ SpecC…² Syncode Stock…³ Genus…⁴ Speci…⁵ ColName PicName
     <int>         <int>   <int>   <int>   <int> <chr>   <chr>   <chr>   <chr>  
 1   34424         36653     227   22902     241 "Megal… "cypri… "Megal… ""     
 2   95154         45880      NA      NA      NA ""      ""      ""      ""     
 3   97606         45880      NA      NA      NA ""      ""      ""      ""     
 4  100025         45880    5520   25676    5809 "Johni… "belan… ""      ""     
 5   98993         45880    5676   16650    5969 "Chrom… "retro… ""      ""     
 6   99316         45880     454   23112     468 "Drepa… "punct… ""      ""     
 7   99676         45880    5388  145485    5647 "Gymno… "bosch… ""      ""     
 8   99843         45880   16813  119925   15264 "Hemir… "balin… ""      ""     
 9  100607         45880    8288   59635    8601 "Ostra… "rhino… ""      ""     
10  101529         45880      NA      NA      NA "Scomb… "toloo… ""      ""     
# … with 1,097,293 more rows, 97 more variables: CatNum <chr>, URL <chr>,
#   Station <chr>, Cruise <chr>, Gazetteer <chr>, LocalityType <chr>,
#   WaterDepthMin <dbl>, WaterDepthMax <dbl>, AltitudeMin <int>,
#   AltitudeMax <int>, LatitudeDeg <int>, LatitudeMin <dbl>, NorthSouth <chr>,
#   LatitudeDec <dbl>, LongitudeDeg <int>, LongitudeMIn <dbl>, EastWest <chr>,
#   LongitudeDec <dbl>, Accuracy <chr>, Salinity <chr>, LatitudeTo <dbl>,
#   LongitudeTo <dbl>, LatitudeDegTo <int>, LatitudeMinTo <dbl>, …

Local copy

Set the option “rfishbase_local_db” = TRUE to create a local copy, otherwise will use a remote copy. Local copy will get better performance after initial import, but may experience conflicts when duckdb is upgraded or when multiple sessions attempt to access the directory. Remove the default storage directory (given by db_dir()) after upgrading duckdb if using a local copy.

options("rfishbase_local_db" = TRUE)
db_disconnect() # close previous remote connection

conn <- fb_conn()
conn
<duckdb_connection 5fa20 driver=<duckdb_driver 543a0 dbdir='/home/cboettig/.local/share/R/rfishbase/fishbase_23.01' read_only=FALSE bigint=numeric>>

Users can trigger a one-time download of all fishbase tables (or a list of desired tables) using fb_import(). This will ensure later use of any function can operate smoothly even when no internet connection is available. Any table already downloaded will not be re-downloaded. (Note: fb_import() also returns a remote duckdb database connection to the tables, for users who prefer to work with the remote data objects.)

fb_import()
<duckdb_connection 5fa20 driver=<duckdb_driver 543a0 dbdir='/home/cboettig/.local/share/R/rfishbase/fishbase_23.01' read_only=FALSE bigint=numeric>>

Interactive RStudio pane

RStudio users can also browse all fishbase tables interactively in the RStudio connection browser by using the function fisbase_pane(). Note that this function will first download a complete set of the fishbase tables.

Backwards compatibility

rfishbase 4.0 tries to maintain as much backwards compatibility as possible with rfishbase 3.0. Because parquet preserves native data types, some encoded types may differ from earlier versions. As before, these are not always the native type – e.g. fishbase encodes some boolean (logical TRUE/FALSE) values as integer (-1, 0) or character types. Use as.logical() to coerce into the appropriate type in that case.

Toggling between fishbase and sealifebase servers using an environmental variable, FISHBASE_API, is now deprecated.

Note that fishbase will store downloaded files by hash in the app directory, given by db_dir(). The default location can be set by configuring the desired path in the environmental variable, FISHBASE_HOME.


Please note that this package is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

ropensci_footer

More Repositories

1

drake

An R-focused pipeline toolkit for reproducibility and high-performance computing
R
1,328
star
2

skimr

A frictionless, pipeable approach to dealing with summary statistics
HTML
1,090
star
3

targets

Function-oriented Make-like declarative workflows for R
R
829
star
4

rtweet

🐦 R client for interacting with Twitter's [stream and REST] APIs
R
785
star
5

tabulizer

Bindings for Tabula PDF Table Extractor Library
R
518
star
6

pdftools

Text Extraction, Rendering and Converting of PDF Documents
C++
489
star
7

assertr

Assertive programming for R analysis pipelines
R
457
star
8

magick

Magic, madness, heaven, sin
R
440
star
9

visdat

Preliminary Exploratory Visualisation of Data
R
439
star
10

stplanr

Sustainable transport planning with R
R
410
star
11

RSelenium

An R client for Selenium Remote WebDriver
R
332
star
12

rnoaa

R interface to many NOAA data APIs
R
320
star
13

osmdata

R package for downloading OpenStreetMap data
C++
305
star
14

charlatan

Create fake data in R
R
283
star
15

software-review

rOpenSci Software Peer Review.
R
274
star
16

iheatmapr

Complex, interactive heatmaps in R
R
259
star
17

taxize

A taxonomic toolbelt for R
R
250
star
18

rrrpkg

Use of an R package to facilitate reproducible research
248
star
19

elastic

R client for the Elasticsearch HTTP API
R
244
star
20

tesseract

Bindings to Tesseract OCR engine for R
R
236
star
21

qualtRics

Download ⬇️ Qualtrics survey data directly into R!
R
207
star
22

git2r

R bindings to the libgit2 library
C
204
star
23

writexl

Portable, light-weight data frame to xlsx exporter for R
C
202
star
24

biomartr

Genomic Data Retrieval with R
R
201
star
25

rnaturalearth

An R package to hold and facilitate interaction with natural earth map data 🌍
R
191
star
26

googleLanguageR

R client for the Google Translation API, Google Cloud Natural Language API and Google Cloud Speech API
HTML
189
star
27

textreuse

Detect text reuse and document similarity
R
188
star
28

tokenizers

Fast, Consistent Tokenization of Natural Language Text
R
179
star
29

rentrez

talk with NCBI entrez using R
R
178
star
30

piggyback

📦 for using large(r) data files on GitHub
R
172
star
31

rcrossref

R client for various CrossRef APIs
R
159
star
32

osmextract

Download and import OpenStreetMap data from Geofabrik and other providers
R
157
star
33

dataspice

🌶️ Create lightweight schema.org descriptions of your datasets
R
155
star
34

tic

Tasks Integrating Continuously: CI-Agnostic Workflow Definitions
R
154
star
35

webchem

Chemical Information from the Web
R
149
star
36

geojsonio

Convert many data formats to & from GeoJSON & TopoJSON
R
148
star
37

MODIStsp

An "R" package for automatic download and preprocessing of MODIS Land Products Time Series
R
147
star
38

rgbif

Interface to the Global Biodiversity Information Facility API
R
145
star
39

DataPackageR

An R package to enable reproducible data processing, packaging and sharing.
R
145
star
40

tsbox

tsbox: Class-Agnostic Time Series in R
R
143
star
41

dev_guide

rOpenSci Packages: Development, Maintenance, and Peer Review
R
141
star
42

jqr

R interface to jq
R
139
star
43

ghql

GraphQL R client
R
136
star
44

osfr

R interface to the Open Science Framework (OSF)
R
135
star
45

osmplotr

Data visualisation using OpenStreetMap objects
R
130
star
46

opencv

R bindings for OpenCV
C++
130
star
47

ssh

Native SSH client in R based on libssh
C
126
star
48

RefManageR

R package RefManageR
R
112
star
49

spocc

Species occurrence data toolkit for R
R
109
star
50

tarchetypes

Archetypes for targets and pipelines
R
107
star
51

ezknitr

Avoid the typical working directory pain when using 'knitr'
R
107
star
52

hunspell

High-Performance Stemmer, Tokenizer, and Spell Checker for R
C++
106
star
53

crul

R6 based http client for R (made for developers)
R
101
star
54

gistr

Interact with GitHub gists from R
R
101
star
55

spelling

Tools for Spell Checking in R
R
101
star
56

weathercan

R package for downloading weather data from Environment and Climate Change Canada
R
99
star
57

git2rdata

An R package for storing and retrieving data.frames in git repositories.
R
98
star
58

bib2df

Parse a BibTeX file to a tibble
R
97
star
59

ckanr

R client for the CKAN API
R
97
star
60

gutenbergr

Search and download public domain texts from Project Gutenberg
R
95
star
61

rsvg

SVG renderer for R based on librsvg2
C
95
star
62

nasapower

API Client for NASA POWER Global Meteorology, Surface Solar Energy and Climatology in R
R
92
star
63

EML

Ecological Metadata Language interface for R: synthesis and integration of heterogenous data
R
92
star
64

cyphr

:shipit: Humane encryption
R
91
star
65

FedData

Functions to Automate Downloading Geospatial Data Available from Several Federated Data Sources
R
88
star
66

av

Working with Video in R
C
88
star
67

mapscanner

R package to print maps, draw on them, and scan them back in
R
87
star
68

UCSCXenaTools

📦 An R package for accessing genomics data from UCSC Xena platform, from cancer multi-omics to single-cell RNA-seq https://cran.r-project.org/web/packages/UCSCXenaTools/
R
87
star
69

opencage

🌐 R package for the OpenCage API -- both forward and reverse geocoding 🌐
R
86
star
70

tidync

NetCDF exploration and data extraction
R
85
star
71

GSODR

API Client for Global Surface Summary of the Day ('GSOD') Weather Data Client in R
R
82
star
72

rzmq

R package for ZMQ
C++
82
star
73

bikedata

🚲 Extract data from public hire bicycle systems
R
79
star
74

historydata

Datasets for Historians
R
78
star
75

dittodb

dittodb: A Test Environment for DB Queries in R
R
78
star
76

arkdb

Archive and unarchive databases as flat text files
R
78
star
77

fingertipsR

R package to interact with Public Health England’s Fingertips data tool
R
78
star
78

smapr

An R package for acquisition and processing of NASA SMAP data
R
77
star
79

vcr

Record HTTP calls and replay them
R
76
star
80

nodbi

Document DBI connector for R
R
75
star
81

CoordinateCleaner

Automated flagging of common spatial and temporal errors in biological and palaeontological collection data, for the use in conservation, ecology and palaeontology.
HTML
74
star
82

openalexR

Getting bibliographic records from OpenAlex
R
74
star
83

opentripplanner

An R package to set up and use OpenTripPlanner (OTP) as a local or remote multimodal trip planner.
R
73
star
84

nlrx

nlrx NetLogo R
R
71
star
85

rebird

Wrapper to the eBird API
R
70
star
86

gittargets

Data version control for reproducible analysis pipelines in R with {targets}.
R
69
star
87

tidyhydat

An R package to import Water Survey of Canada hydrometric data and make it tidy
R
69
star
88

robotstxt

robots.txt file parsing and checking for R
R
68
star
89

slopes

Package to calculate slopes of roads, rivers and trajectories
R
65
star
90

tradestatistics

R package to access Open Trade Statistics API
R
65
star
91

terrainr

Get DEMs and orthoimagery from the USGS National Map, georeference your images and merge rasters, and visualize with Unity 3D
R
64
star
92

unconf17

Website for 2017 rOpenSci Unconf
JavaScript
64
star
93

NLMR

📦 R package to simulate neutral landscape models 🏔
R
63
star
94

roadoi

Use Unpaywall with R
R
63
star
95

parzer

Parse geographic coordinates
R
63
star
96

tiler

Generate geographic and non-geographic map tiles from R
R
63
star
97

rb3

A bunch of downloaders and parsers for data delivered from B3
R
62
star
98

rWBclimate

R interface for the World Bank climate data
R
62
star
99

codemetar

an R package for generating and working with codemeta
R
62
star
100

aRxiv

Programmatic interface to the Arxiv API
R
58
star