Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update feedr v1.0.0 #19

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on: [push, pull_request]
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
Expand All @@ -14,7 +20,7 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
Expand All @@ -25,23 +31,22 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2

- name: macOS dependencies
if: runner.os == 'macOS'
run: |
brew install gdal proj
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v1
- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v1
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: rcmdcheck
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v1
- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
9 changes: 4 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: feedr
Type: Package
Title: Transforming Raw RFID Data
Version: 0.11.0
Version: 0.11.0.9000
Authors@R: person("Steffi", "LaZerte", email = "[email protected]", role = c("aut","cre"))
URL: https://github.com/animalnexus/feedr
Description: Load, clean, transform, and visualize raw RFID data for looking at a variety of
Expand All @@ -16,25 +16,24 @@ Imports:
leaflet (>= 2.0.4.1),
lubridate (>= 1.7.10),
magrittr (>= 2.0.1),
maptools (>= 1.1.1),
rlang (>= 0.4.12),
purrr (>= 0.3.4),
scales (>= 1.1.1),
stringr (>= 1.4.0),
tibble (>= 3.1.2),
tidyr (>= 1.1.3)
tidyr (>= 1.1.3),
suncalc (>= 0.5.1)
Suggests:
activity,
aniDom,
asnipe,
Dominance,
knitr,
Perc,
png,
rmarkdown,
sp,
testthat (>= 3.0.0)
RoxygenNote: 7.1.2
RoxygenNote: 7.3.1
VignetteBuilder: knitr
Roxygen: list(markdown = TRUE)
Encoding: UTF-8
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export(map_ggmap)
export(map_leaflet)
export(move)
export(presence)
export(sun)
export(tz_offset)
export(visits)
import(leaflet)
Expand Down
34 changes: 11 additions & 23 deletions R/convert.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,13 @@ convert_anidom <- function(d){
}


#' Convert displacements for use by functions from the Dominance package
#' DEFUNCT - Convert displacements for use by functions from the Dominance package
#'
#' **The Dominance package is no longer available therefore this function
#' is defunct**
#'
#' Converts displacements RFID data into a format for easy use by either the
#' [Dominance::ADI()] or the [Dominance::Sociogram()]
#' `Dominance::ADI()` or the `Dominance::Sociogram()`
#' functions included in the Dominance package for calculating average
#' dominance indices and drawing sociograms. Only includes individuals that
#' participated in at least one interaction.
Expand All @@ -177,29 +180,14 @@ convert_anidom <- function(d){
#' vector indicating that the action type "displacement" should be included in
#' the calculation. See examples for specific application.
#'
#' @seealso Dominance package and it's functions: [Dominance::ADI] and [Dominance::Sociogram]. <https://cran.r-project.org/package=Dominance>
#'
#' @examples
#' # Calculate displacements
#' d <- disp(visits(finches_lg))
#'
#' # Format for use by Dominance package
#' i <- convert_dominance(d)
#' i <- convert_dominance(d$displacements) # Equivalent
#'
#' \dontrun{
#' # Use Dominance package:
#' library(Dominance)
#'
#' # Calculate the Average Dominance Index
#' ADI(data_sheet = i$data_sheet, items = i$items, actions = i$actions, bytes = i$bytes)
#'
#' # Construct social network graphs
#' Sociogram(data_sheet = i$data_sheet, items = i$items, actions = i$actions, bits = i$bytes)
#' }
#'
#' @export

convert_dominance <- function(d) {

stop("The Dominance package is no longer available therefore this function ",
"is defunct", call. = FALSE)


# Function takes either the whole output of disp() or just the displacements
if(!is.data.frame(d)) d <- d$displacements

Expand Down
9 changes: 5 additions & 4 deletions R/maps.R
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ map_leaflet_base <- function(locs, marker = "logger_id",
options = leaflet::leafletOptions(minZoom = minZoom,
maxZoom = maxZoom)) %>%
leaflet::addTiles(group = "Open Street Map") %>%
leaflet::addProviderTiles("Stamen.Toner", group = "Black and White") %>%
leaflet::addProviderTiles("Esri.WorldImagery", group = "Satellite") %>%
leaflet::addProviderTiles("Esri.WorldTopoMap", group = "Terrain") %>%
leaflet::addProviderTiles(providers$Stadia.StamenToner, group = "Black and White") %>%
leaflet::addProviderTiles(providers$Esri.WorldImagery, group = "Satellite") %>%
leaflet::addProviderTiles(providers$Esri.WorldTopoMap, group = "Terrain") %>%
leaflet::addCircleMarkers(~lon, ~lat,
popup = htmltools::htmlEscape(
paste("Logger:",
Expand Down Expand Up @@ -467,6 +467,7 @@ map_ggmap <- function() {
.Defunct()
}


map.ggmap <- function() {
.Defunct()
.Defunct()
}
34 changes: 9 additions & 25 deletions R/transformations.R
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ disp <- function(v, bw = 2, pass = TRUE){
c("animal_id", "logger_id", "date", "start", "end")])

if(nrow(d) > 0) {

d <- d %>%
dplyr::arrange(.data$start) %>%
dplyr::mutate(role = rep(c("displacee", "displacer"), dplyr::n()/2)) %>%
Expand All @@ -859,6 +860,7 @@ disp <- function(v, bw = 2, pass = TRUE){
s <- d %>%
dplyr::group_by(role, animal_id) %>%
dplyr::summarize(n = length(animal_id)) %>%
dplyr::ungroup() %>%
tidyr::complete(animal_id, role, fill = list("n" = 0)) %>%
tidyr::spread(role, n) %>%
dplyr::mutate(p_win = displacer / (displacee + displacer)) %>%
Expand Down Expand Up @@ -1098,11 +1100,13 @@ activity_single <- function(p1, loggers, res = 15, by_logger = FALSE, missing =
message(paste0(p1$animal_id[1], ": Skipping sunrise/sunset, no lat/lon information"))
} else {

s <- expand.grid(logger_id = loggers$logger_id,
date = lubridate::as_date(seq(start, end, by = "1 day"))) %>%
dplyr::left_join(unique(loggers[, c("logger_id", "lon", "lat")]), by = "logger_id")

s <- dplyr::bind_cols(s, sun(s[, c("lon", "lat")], s$date, tz = tz))
s <- tidyr::expand_grid(
date = lubridate::as_date(seq(start, end, by = "1 day")),
dplyr::distinct(loggers[, c("lon", "lat")])) |>
suncalc::getSunlightTimes(data = _, keep = c("sunrise", "sunset")) |>
dplyr::rename("rise" = "sunrise", "set" = "sunset") |>
dplyr::left_join(x = loggers, y = _, by = c("lat", "lon"),
relationship = "many-to-many")

if(by_logger == TRUE) {
a <- dplyr::left_join(a, s[, c("logger_id", "date", "rise", "set")],
Expand Down Expand Up @@ -1209,23 +1213,3 @@ daily_single <- function(a1, pass = TRUE){
dplyr::select(d, dplyr::all_of(n)) %>%
dplyr::arrange(animal_id, time)
}

#' Get sunrise/sunset times
#'
#' Calculate times of sunrise and sunset depending on the location and the date.
#'
#' @param loc Vector/Data frame. Longitude and Latitude coordinates for location
#' of sun rise/set
#' @param date Vector. Date(s) to cacluate sun rise/set for.
#' @param tz Timezone of the dates.
#'
#' @export
sun <- function(loc, date, tz) {
if(class(loc) == "numeric") loc <- matrix(loc, nrow = 1)
if(class(loc) %in% c("data.frame", "matrix")) loc <- as.matrix(loc)
date <- as.POSIXct(as.character(date), tz = tz)
s <- data.frame(rise = maptools::sunriset(loc, date, direction = "sunrise", POSIXct.out = TRUE)$time,
set = maptools::sunriset(loc, date, direction = "sunset", POSIXct.out = TRUE)$time)

return(s)
}
31 changes: 6 additions & 25 deletions man/convert_dominance.Rd

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

19 changes: 0 additions & 19 deletions man/sun.Rd

This file was deleted.

8 changes: 8 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(feedr)

Expand Down
Loading
Loading