library(tidyverse)
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

oceandf

Lifecycle: experimental R build status

The goal of oceandf is to read ODF files. You can already do this using oce::read.odf() and other internal Fisheries and Oceans Canada tools; this package allows more flexible reading using the readr package and using data frames wherever possible.

Installation

You can install the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("paleolimbot/oceandf")

Example

Read ODF files as tables, guessing column types and names from the PARAMTER_HEADER:

library(oceandf)
odf_file <- odf_example("CTD_98911_10P_11_DN.ODF")
read_odf(odf_file)

You can also read ODF headers as a list of data frames with reasonable guesses for column types:

read_odf_header(odf_file)

The header as a list() of tibble() makes it particularly well-suited to comparing headers from many files:

library(tidyverse)

odf_files <- c(
  odf_example("CTD_98911_10P_11_DN.ODF"),
  odf_example("CTD_PRD2002-001_26_1_DN.ODF")
)

odf_files %>%
  set_names() %>% 
  map_dfr(read_odf_header_tbl, "CRUISE_HEADER", .id = "file")

The read_odf() and read_odf_header() functions were carefully designed to report parse errors rather than fail for creatively formatted ODF files:

odf_file <- odf_example("MADCP_PRD2014001_1878_2456-OPTS_7200.ODF")
read_odf_header_tbl(odf_file, "CRUISE_HEADER")

You can override the default guesses for headers using odf_header_cols_default() or readr::cols():

read_odf_header_tbl(
  odf_file, "CRUISE_HEADER", 
  col_types = odf_header_cols_default(
    START_DATE = odf_col_date(),
    END_DATE = odf_col_date()
  )
)

read_odf_header_tbl(
  odf_file, "CRUISE_HEADER", 
  col_types = readr::cols(.default = col_character())
)

read_odf_header(odf_file, default_col_types = readr::cols())


paleolimbot/oceandf documentation built on March 9, 2021, 9:43 a.m.