knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
The aim of this document is to outline the basic workflow of importing data downloaded from the ICES Regional Database & Estimation System (RDBES) or a list
object containing data frames (or data.tables) into R
using the RDBEScore
package.
The function createRDBESDataObject is intended to directly import Commercial Landing (CL), Commercial Effort (CE) and Commercial Sampling (CS) tables downloaded from RDBES.
library(RDBEScore)
#the directory holding the data to import dataDir <- "./yourDataDirectory/" #for demonstration purposes we will use the example data included in the package dataDir <- paste0(system.file("extdata", package = "RDBEScore"), "/")
It can directly import the .zip
archive from the RDBES download containing all mandatory hierarchy tables plus VD and SL:
importedH1 <- createRDBESDataObject(input = paste0(dataDir,"H1_Example.zip")) #print the not NULL table names names(importedH1[!unlist(lapply(importedH1, is.null))])
The easiest way to get a glimpse of the imported data hierarchy and single table row counts is just to print it. The information also includes the range of number sampled and number total for each table together with the selection method and number of rows.
#calls the print function
importedH1
It can import the CL, CE, VD or SL tables .zip
archives, but will include all other tables as NULL
:
importedSL <- createRDBESDataObject(input = paste0(dataDir,"HSL_Example.zip")) #print the not NULL table names importedSL
It can also handle overwriting zip
file original files with files appearing later in the list. However each overwrite results in a warning!
importFiles <- c(paste0(dataDir,"HSL_Example.zip"), paste0(dataDir,"H1_Example.zip")) importedTables <- createRDBESDataObject(input = importFiles) #print the not NULL table names names(importedTables[!unlist(lapply(importedTables, is.null))])
It can also import the unzipped .csv
files with the default RDBES names:
importedVS <- createRDBESDataObject(input = dataDir, listOfFileNames = list("VS" = "VesselSelection.csv")) #print the not NULL table names names(importedVS[!unlist(lapply(importedVS, is.null))])
It can also import a list
object containing data frames (or data.tables). However, it should be noted that this type of import bypasses the RDBES upload data integrity checks.
#list of data frames listOfDfsH1 <- readRDS(paste0(dataDir,"H1_Example.rds")) #print the class of the list elements sapply(listOfDfsH1, class)
importedList <- createRDBESDataObject(listOfDfsH1)
It should be noted that the objects created are of the S3 class "RDBESDataObject". The class has defined print(), summary() and sort() methods. For more info on theese see vignette Manipulating RDBESDataObjects.
importedTables <- createRDBESDataObject(paste0(dataDir,"H1_Example.zip")) class(importedTables)
RDBESDataObject structure can be validated using the validateRDBESDataObject() function.
validateRDBESDataObject(importedTables, verbose = TRUE)
To see what you can do with the imported RDBESDataObject see other vignettes like Manipulating RDBESDataObjects.
Other vignettes:
vignettes <- as.data.frame(browseVignettes(package = "RDBEScore")$RDBEScore) for (i in seq_along(vignettes$PDF)) { cat(sprintf("- [%s](%s)\n", vignettes$Title[i], vignettes$PDF[i])) } #END
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.