Skip to content

Commit

Permalink
example dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
rosieluain committed Jun 23, 2023
1 parent 64e8ca5 commit 3335cc9
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 8 deletions.
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ Suggests:
plotly,
rmarkdown
VignetteBuilder: knitr
Depends:
R (>= 2.10)
104 changes: 104 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#'Sample acoustic telemetry detection data
#'
#'These detection data were subset from a real acoustic telemetry dataset of Arctic
#'Char near Kugluktuk, Nunavut. The data were from a project that was a
#'collaboration between the Kugluktuk Hunters and Trappers Organization, the
#'University of Waterloo, and Fisheries and Oceans Canada. The data are valuable
#'to the community of Kugluktuk, and are also sensitive due to their pertinence
#'to the local fishery for Arctic Char. For this reason, the detections have been
#'given generic station names and fish IDs so locations and sample information
#'is anonymous. The year has also been changed, but otherwise, the detections are
#'real, and therefore have all the challenges and intricacies of biological
#'data.
#'
#'The variables are as follows:
#'
#'\itemize{
#'\item DateTimeUTC. The date and time of each detection, in POSIXct format. The
#'data are in UTC, as downloaded from the receivers.
#'\item Station.Name Name of the receiver location.
#'\item ID Unique ID of the fish.
#'}
#'
#'@docType data
#'@keywords datasets
#'@name detections
#'@usage data(detections)
#'@format A data frame with 447 627 rows (observations) and 3 variables.
NULL

#'Sample residence events
#'
#'Events generated from the sample detection file provided. Events were generated
#'using the residences() function in mort.
#'
#'The detection data were subset from a real acoustic telemetry dataset of Arctic
#'Char near Kugluktuk, Nunavut. The data were from a project that was a
#'collaboration between the Kugluktuk Hunters and Trappers Organization, the
#'University of Waterloo, and Fisheries and Oceans Canada. The data are valuable
#'to the community of Kugluktuk, and are also sensitive due to their pertinence
#'to the local fishery for Arctic Char. For this reason, the detections have been
#'given generic station names and fish IDs so locations and sample information
#'is anonymous. The year has also been changed, but otherwise, the detections are
#'real, and therefore have all the challenges and intricacies of biological
#'data.
#'
#'The variables are as follows:
#'
#'\itemize{
#'\item ResidenceStart. The start time of the residence events, in POSIXct.
#'\item Station.Name. Name of the receiver location.
#'\item ID. Unique ID of the fish.
#'\item ResidenceEnd. The end time of the residence events, in POSIXct.
#'\item ResidenceLength.days. The duration of the residence events. The units are
#'days, as indicated by the variable name (which is automatically generated
#'by mort::residences())
#'}
#'
#'@docType data
#'@keywords datasets
#'@name events
#'@usage data(events)
#'@format A data frame with 11 487 rows (events) and 5 variables.
NULL

#'Sample dead drift direction dataframe
#'
#'The locations have been given generic station names, due to the sensitive nature
#'of the dataset. The connections between stations (i.e., which stations are
#'connected by drift and in which direction) are real.
#'
#'The variables are as follows:
#'
#'\itemize{
#'\item From. The station where a tag may drift from.
#'\item To. The station where a tag may drift to, from the station in From.
#'}
#'
#'@docType data
#'@keywords datasets
#'@name ddd
#'@usage data(ddd)
#'@format A data frame with 18 rows and 2 variables.
NULL

#'Ice-free seasons
#'
#'The year has been changed, due to the sensitive nature of the dataset. The
#'years have been changed in the same manner as the detection dates, so
#'the ice-free dates correspond to the dataset in the same way as the original
#'dataset.
#'
#'The variables are as follows:
#'
#'\itemize{
#'\item Start. The date of ice break-up (the start of the period of interest).
#'\item End. The date of ice freeze-up (the end of the period of interest).
#'}
#'
#'@docType data
#'@keywords datasets
#'@name seasons
#'@usage data(seasons)
#'@format A data frame with 5 rows (years) and 2 variables.
NULL
4 changes: 2 additions & 2 deletions R/residences.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#' @importFrom utils setTxtProgressBar txtProgressBar
#'
#' @examples
#' \dontrun{residences(data=data,ID="TagID",station="Receiver",
#'# datetime="DateTimeUTC",cutoff=1,units="days")}
#' \dontrun{residences(data=detections,ID="TagID",station="Receiver",
#' datetime="DateTimeUTC",cutoff=1,units="days")}

residences<-function(data,ID,station,datetime,cutoff,units){
# Create list of unique IDs
Expand Down
24 changes: 18 additions & 6 deletions R/stationchange.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#' @param to.station a string of the name of the column in `ddd` that contains
#' the station/location names where drifting detections may move to. Must
#' be identical to the station/location names in `data`.
#' @param progressbar option to display progress bar as function is run. Default
#' is TRUE.
#'
#' @return a dataframe with one row for each tag ID, including the date/time of
#' the residence start at the most recent station or location, the date/time of
Expand All @@ -47,7 +49,7 @@
stationchange<-function(data,type="mort",ID,station,res.start="auto",
res.end="auto",residences="auto",
singles=TRUE,drift=FALSE,ddd=NULL,units=NULL,from.station=NULL,
to.station=NULL){
to.station=NULL,progressbar=TRUE){

if (type %in% c("actel","vtrack")&is(data,"list")){
data<-extractres(data=data,type=type)
Expand Down Expand Up @@ -91,7 +93,9 @@ stationchange<-function(data,type="mort",ID,station,res.start="auto",

if (drift==FALSE&
!is(data[[station]],"list")){
pb<-txtProgressBar(1,length(tag),style=3)
if (progressbar==TRUE){
pb<-txtProgressBar(1,length(tag),style=3)
}
for (i in 1:length(tag)){
res.temp<-data[data[[ID]]==tag[i],]
# Order by time
Expand Down Expand Up @@ -130,7 +134,9 @@ stationchange<-function(data,type="mort",ID,station,res.start="auto",
else if (nrow(res.temp)==1){
stn.change[nrow(stn.change)+1,]<-res.temp[1,]
}
setTxtProgressBar(pb,i)
if (progressbar==TRUE){
setTxtProgressBar(pb,i)
}
}
}

Expand Down Expand Up @@ -208,6 +214,8 @@ stationchange<-function(data,type="mort",ID,station,res.start="auto",
#' recent station or location change. Must use the same column names as `data`.
#' @param drift indicates if drift residence events should be included in
#' determining the maximum residence duration
#' @param progressbar option to display progress bar as function is run. Default
#' is TRUE.
#'
#' @return a dataframe with the residence information for the longest residence
#' for each tag ID that occurred before the most recent station/location change.
Expand All @@ -217,10 +225,12 @@ stationchange<-function(data,type="mort",ID,station,res.start="auto",
#' \dontrun{resmax(data=res.events,ID="TagID",station="Receiver",
#' res.start="StartUTC",residences="ResidencesLength.days",stnchange=station.change)}
resmax<-function(data,ID,station,res.start,
residences,stnchange,drift=FALSE){
residences,stnchange,drift=FALSE,progressbar=TRUE){
res.max<-data[0,]

pb<-txtProgressBar(1,nrow(stnchange),style=3)
if (progressbar==TRUE){
pb<-txtProgressBar(1,nrow(stnchange),style=3)
}
for (i in 1:nrow(stnchange)){
# Subset residences for ID i, where res.start < res.start of stnchange
res.temp<-data[data[[ID]]==stnchange[[ID]][i]&
Expand All @@ -245,7 +255,9 @@ resmax<-function(data,ID,station,res.start,
}
}
}
setTxtProgressBar(pb,i)
if (progressbar==TRUE){
setTxtProgressBar(pb,i)
}
}

res.max
Expand Down
Binary file added data/ddd.rda
Binary file not shown.
Binary file added data/detections.rda
Binary file not shown.
Binary file added data/events.rda
Binary file not shown.
Binary file added data/seasons.rda
Binary file not shown.
26 changes: 26 additions & 0 deletions man/ddd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions man/detections.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions man/events.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions man/seasons.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3335cc9

Please sign in to comment.