Skip to contents

Computes fishing effort (hours) for each interview row using a conditional rule: if the time_fished column is present and non-NA for a row, use that value (angler self-reported hours, e.g. after a break); otherwise compute from timestamps as difftime(interview_time, trip_start, units = "hours").

This function can be called standalone on raw data before entering the add_interviews workflow, or used to preprocess a column that will be passed as the effort argument to add_interviews().

Usage

compute_effort(data, trip_start, interview_time, time_fished = NULL)

Arguments

data

A data frame containing the interview records.

trip_start

Tidy selector for the trip start timestamp column (POSIXct).

interview_time

Tidy selector for the interview timestamp column (POSIXct).

time_fished

Optional tidy selector for a self-reported hours column. When a row has a non-NA value here, it overrides the timestamp calculation. Default is NULL (always compute from timestamps).

Value

The input data frame with an added .effort column (numeric, hours). Existing columns are preserved.

Examples

trips <- data.frame(
  trip_start     = as.POSIXct(c("2024-06-01 08:00:00", "2024-06-01 09:15:00")),
  interview_time = as.POSIXct(c("2024-06-01 10:30:00", "2024-06-01 12:00:00"))
)
compute_effort(trips, trip_start, interview_time)
#>            trip_start      interview_time .effort
#> 1 2024-06-01 08:00:00 2024-06-01 10:30:00    2.50
#> 2 2024-06-01 09:15:00 2024-06-01 12:00:00    2.75