repository | monitorgonio | io home

sattagutils is under active development... things will change. If you'd like to contribute take a look at the readme and contributing files.

sattagutils

I've put together some of the functions I use most often when manipulating Wildlife Computer's satellite tags (especially SPLASH10s). This package isn't on CRAN yet, though I hope a future release will be. For now you can download and install or use devtools.

Skip to the Quick guide if you don't care about how the thing works. Perhaps the most useful functionality of sattagutils is that it'll load a single tag or a directory of tags into R automatically dealing with all of the irregularities and inconsistencies in file and date formats. I've also included a handful of plotting and other tools that I tend to use a lot when I'm browsing tags.

Central concepts

S4 object system

Tag data streams are essentially tables with some metadata attached to them. I thought of tags as lists of data.frames with some additional metadata attached to them.

In the end I settled on S4 classes to represent tag and data objects. I know some people hate them, but in the end it seemed like the most sensible thing to do. I couldn't get the seamless functionality that I wanted out of S3. Similarly, the other OO systems in R would've gotten in the way, I think. For most operations I wanted tables to behave just like tables.

es4dataframe

All of the various sattag data streams inherit es4dataframe:

setClass("es4dataframe",
  contains = "data.frame"
)

and a constructor:

es4dataframe <- function(..., stringsAsFactors = FALSE) {
  data <- data.frame(..., stringsAsFactors = stringsAsFactors)
  new("es4dataframe", data)
}

I implemented only the most basic functionality that I needed including as.data.frame, is.es4dataframe, $, [, [<-, and merge although I kind of regret that last one.

Most are fairly simple and just pass the buck to the underlying data.frame. For example:

setMethod("[<-", "es4dataframe", function(x, i, j, ..., value) {
  dfin <- as.data.frame(x)
  dfout <- getS3method("[<-", "data.frame")(dfin, i, j, ..., value)

  x@.Data <- dfout
  x@names <- names(dfout)
  x@row.names <- rownames(dfout)

  return(x)
})

sattagstream

A satagstream a es4dataframe with a couple of extra slots for the type of stream and the original filename that was loaded for the stream. There are various subclass options for sattagstreams and mostly you don't need to worry about it, the primary uses are importing correctly from the badly formated Wildlife Computer csvs and guessing date formats correctly.

sattag and tagstack

A sattag is a list with slots for instrument, DeployID, Ptt, species, location, start, end times, directory, and load date.

And finally a tagstack is a list of sattag objects with an extra slot for the directory the stack was loaded from. This is a little overkill probably it could have been just a regular list, but I was committed to keeping the metadata with the data at this point.

sattag has its own constructor and a variety of get and set methods for the slots. [ also had to be defined explicitly to get things working as you'd expect (that is [ should return a sattag and [[ should return a sattagstream), but other than that lists behave a little better than data.frames do. tagstack also has a constructor and [ as well as some get and set methods.

Everything has nice show methods so you don't blow up your console peeking at tags.

Quick guide {#sattagutils-quickguide}

Install and load

devtools::install_github("williamcioffi/sattagutils")
library(sattagutils)

the basics:

you probably want to start with:

?sattagutils
?load_tag
?batch_load_tags


williamcioffi/sattagutils documentation built on June 3, 2022, 10:21 a.m.