Skip to content

Commit

Permalink
fix dplyr::filter stats::filter conflicts;
Browse files Browse the repository at this point in the history
replace %>% with |>
  • Loading branch information
Ian Jonsen committed Oct 17, 2023
1 parent e8523b6 commit b3baf49
Show file tree
Hide file tree
Showing 21 changed files with 161 additions and 180 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: aniMotum
Title: Fit Continuous-Time State-Space and Latent Variable Models for Quality Control of Argos Satellite (and Other) Telemetry Data and for Estimating Changes in Animal Movement
Version: 1.1-01.9061
Version: 1.1-01.9075
Date: 2023-09-18
Authors@R:
c(
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ importFrom(TMB,MakeADFun)
importFrom(TMB,newtonOption)
importFrom(TMB,oneStepPredict)
importFrom(TMB,sdreport)
importFrom(dplyr,"%>%")
importFrom(dplyr,arrange)
importFrom(dplyr,bind_cols)
importFrom(dplyr,bind_rows)
importFrom(dplyr,count)
importFrom(dplyr,distinct)
importFrom(dplyr,everything)
importFrom(dplyr,filter)
importFrom(dplyr,first)
importFrom(dplyr,full_join)
importFrom(dplyr,group_by)
Expand Down
4 changes: 2 additions & 2 deletions R/aniMotum-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
##'
##' @keywords aniMotum
##' @importFrom utils data flush.console globalVariables
##' @importFrom dplyr %>% select mutate slice group_by
##' @importFrom dplyr distinct arrange filter left_join lag full_join bind_cols
##' @importFrom dplyr select mutate slice group_by
##' @importFrom dplyr distinct arrange left_join lag full_join bind_cols
##' @importFrom dplyr summarise
##' @importFrom tibble as_tibble tibble
##' @importFrom sf st_as_sf st_set_crs st_transform st_is_longlat st_crs
Expand Down
12 changes: 0 additions & 12 deletions R/fmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@
##' @param rev reverse colour palette (logical)
##' @param last_loc colour to render last location of each track (default = NULL)
##' @param ... additional arguments passed to [ggspatial::annotation_map_tile]
##' @importFrom ggplot2 ggplot geom_sf aes aes_string ggtitle xlim ylim unit
##' @importFrom ggplot2 element_text theme scale_fill_gradientn scale_fill_manual
##' @importFrom ggplot2 element_blank scale_colour_manual scale_colour_gradientn
##' @importFrom ggplot2 element_line coord_sf
##' @importFrom sf st_bbox st_transform st_crop st_as_sf st_as_sfc st_buffer
##' @importFrom sf st_crs st_coordinates st_cast st_multipolygon st_polygon st_union
##' @importFrom sf st_make_valid
##' @importFrom utils data
##' @importFrom grDevices extendrange grey
##' @importFrom dplyr group_by summarise
##' @importFrom grDevices hcl.colors
##' @importFrom rnaturalearth ne_countries
##' @export

fmap <- function(x,
Expand Down
54 changes: 27 additions & 27 deletions R/grab.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
##' @return a `tibble` with all individual `tibble`'s appended
##'
##' @importFrom sf st_crs st_coordinates st_transform st_geometry st_as_sf st_set_crs
##' @importFrom dplyr group_by mutate ungroup "%>%" bind_rows
##' @importFrom dplyr group_by mutate ungroup bind_rows
##' @importFrom tibble as_tibble
##'
##' @examples
Expand Down Expand Up @@ -119,26 +119,26 @@ grab <- function(x, what = "fitted", as_sf = FALSE, normalise = FALSE, group = F
}

out <- lapply(1:length(out_lst), function(i) {
st_as_sf(out_lst[[i]], coords = c("lon", "lat")) %>%
st_set_crs("+proj=longlat +datum=WGS84 +no_defs") %>%
st_as_sf(out_lst[[i]], coords = c("lon", "lat")) |>
st_set_crs("+proj=longlat +datum=WGS84 +no_defs") |>
st_transform(prj[[pos]])
})
out <- bind_rows(out)

} else if (any(test)) {
out <- lapply(1:length(out_lst), function(i) {
if(nrow(out_lst[[i]]) >= 1){
st_as_sf(out_lst[[i]], coords = c("lon", "lat")) %>%
st_set_crs("+proj=longlat +datum=WGS84 +no_defs") %>%
st_as_sf(out_lst[[i]], coords = c("lon", "lat")) |>
st_set_crs("+proj=longlat +datum=WGS84 +no_defs") |>
st_transform(prj[[1]])
}
})
out <- bind_rows(out)

}
} else if (nrow(x) == 1) {
out <- st_as_sf(out_lst[[1]], coords = c("lon", "lat")) %>%
st_set_crs("+proj=longlat +datum=WGS84 +no_defs") %>%
out <- st_as_sf(out_lst[[1]], coords = c("lon", "lat")) |>
st_set_crs("+proj=longlat +datum=WGS84 +no_defs") |>
st_transform(prj[[1]])
}

Expand All @@ -162,12 +162,12 @@ grab <- function(x, what = "fitted", as_sf = FALSE, normalise = FALSE, group = F
out <- out[, c("id", "date", "x.se", "y.se", "logit_g", "logit_g.se",
"g", "geometry")]
if(normalise & !group) {
out <- out %>%
group_by(id) %>%
mutate(g = (g - min(g))/(max(g) - min(g))) %>%
out <- out |>
group_by(id) |>
mutate(g = (g - min(g))/(max(g) - min(g))) |>
ungroup()
} else if(normalise & group) {
out <- out %>%
out <- out |>
mutate(g = (g - min(g))/(max(g) - min(g)))
}
out
Expand All @@ -178,12 +178,12 @@ grab <- function(x, what = "fitted", as_sf = FALSE, normalise = FALSE, group = F
out <- out[, c("id", "date", "x.se", "y.se", "logit_g",
"logit_g.se", "g", "geometry")]
if(normalise & !group) {
out <- out %>%
group_by(id) %>%
mutate(g = (g - min(g))/(max(g) - min(g))) %>%
out <- out |>
group_by(id) |>
mutate(g = (g - min(g))/(max(g) - min(g))) |>
ungroup()
} else if(normalise & group) {
out <- out %>%
out <- out |>
mutate(g = (g - min(g))/(max(g) - min(g)))
}
} else {
Expand Down Expand Up @@ -215,12 +215,12 @@ grab <- function(x, what = "fitted", as_sf = FALSE, normalise = FALSE, group = F
out <- out[, c("id", "date", "lon", "lat", "x", "y",
"x.se", "y.se", "logit_g", "logit_g.se", "g")]
if(normalise & !group) {
out <- out %>%
group_by(id) %>%
mutate(g = (g - min(g))/(max(g) - min(g))) %>%
out <- out |>
group_by(id) |>
mutate(g = (g - min(g))/(max(g) - min(g))) |>
ungroup()
} else if(normalise & group) {
out <- out %>%
out <- out |>
mutate(g = (g - min(g))/(max(g) - min(g)))
}
out
Expand All @@ -233,12 +233,12 @@ grab <- function(x, what = "fitted", as_sf = FALSE, normalise = FALSE, group = F
out <- out[, c("id", "date", "lon", "lat", "x", "y", "x.se", "y.se", "logit_g",
"logit_g.se", "g")]
if(normalise & !group) {
out <- out %>%
group_by(id) %>%
mutate(g = (g - min(g))/(max(g) - min(g))) %>%
out <- out |>
group_by(id) |>
mutate(g = (g - min(g))/(max(g) - min(g))) |>
ungroup()
} else if(normalise & group) {
out <- out %>%
out <- out |>
mutate(g = (g - min(g))/(max(g) - min(g)))
}
} else {
Expand Down Expand Up @@ -275,12 +275,12 @@ grab <- function(x, what = "fitted", as_sf = FALSE, normalise = FALSE, group = F
out <- bind_rows(out)
out <- as_tibble(out)
if(normalise & !group) {
out <- out %>%
group_by(id) %>%
mutate(g = (g - min(g))/(max(g) - min(g))) %>%
out <- out |>
group_by(id) |>
mutate(g = (g - min(g))/(max(g) - min(g))) |>
ungroup()
} else if(normalise & group) {
out <- out %>%
out <- out |>
mutate(g = (g - min(g))/(max(g) - min(g)))
}
out
Expand Down
2 changes: 1 addition & 1 deletion R/map.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ map <- function(x,
conf <- lapply(1:nrow(x), function(j)
with(x, elps(x[j], y[j], x.se[j], y.se[j], 90)))
lapply(conf, function(x)
st_polygon(list(x))) %>%
st_polygon(list(x))) |>
st_multipolygon()
})

Expand Down
25 changes: 12 additions & 13 deletions R/map_multi_track_base.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
##' @importFrom ggplot2 ggplot geom_sf aes ggtitle xlim ylim unit
##' @importFrom ggplot2 element_text theme scale_fill_gradientn scale_fill_manual
##' @importFrom ggplot2 element_blank scale_colour_manual scale_colour_gradientn
##' @importFrom ggplot2 element_rect coord_sf
##' @importFrom ggplot2 element_rect coord_sf element_line
##' @importFrom rnaturalearth ne_countries
##' @importFrom sf st_union st_convex_hull st_intersection st_collection_extract
##' @importFrom sf st_sf st_crs st_make_valid st_geometry
##' @importFrom dplyr "%>%"
##'
##' @keywords internal
map_multi_track_base <- function(map_type,
Expand Down Expand Up @@ -58,21 +57,21 @@ map_multi_track_base <- function(map_type,

if (by.date) {
lab_dates <-
with(loc_sf, pretty(seq(min(date), max(date), l = 10), n = 5)) %>% as.Date()
with(loc_sf, pretty(seq(min(date), max(date), l = 10), n = 5)) |> as.Date()
}

prj <- st_crs(loc_sf)

## get worldmap
if (map_type == "default") {
if (requireNamespace("rnaturalearthhires", quietly = TRUE)) {
wm <- ne_countries(scale = 10, returnclass = "sf") %>%
st_transform(crs = prj) %>%
wm <- ne_countries(scale = 10, returnclass = "sf") |>
st_transform(crs = prj) |>
st_make_valid()
if(!silent) cat("using map scale: 10\n")
} else {
wm <- ne_countries(scale = 50, returnclass = "sf") %>%
st_transform(crs = prj) %>%
wm <- ne_countries(scale = 50, returnclass = "sf") |>
st_transform(crs = prj) |>
st_make_valid()
if(!silent) cat("using map scale: 50\n")
}
Expand All @@ -81,12 +80,12 @@ map_multi_track_base <- function(map_type,
if(!is.null(obs_sf)) pts <- obs_sf
else pts <- loc_sf

land <- st_buffer(pts, dist = buffer) %>%
st_union() %>%
st_convex_hull() %>%
st_intersection(wm) %>%
st_collection_extract('POLYGON') %>%
st_sf() %>%
land <- st_buffer(pts, dist = buffer) |>
st_union() |>
st_convex_hull() |>
st_intersection(wm) |>
st_collection_extract('POLYGON') |>
st_sf() |>
st_make_valid()

p <- ggplot() +
Expand Down
27 changes: 13 additions & 14 deletions R/map_multi_track_mp.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
##' @importFrom ggplot2 ggplot geom_sf aes ggtitle xlim ylim unit
##' @importFrom ggplot2 element_text theme scale_fill_gradientn scale_fill_manual
##' @importFrom ggplot2 element_blank scale_colour_manual scale_colour_gradientn
##' @importFrom ggplot2 element_rect coord_sf
##' @importFrom ggplot2 element_rect coord_sf element_line
##' @importFrom rnaturalearth ne_countries
##' @importFrom sf st_union st_convex_hull st_intersection st_collection_extract
##' @importFrom sf st_sf st_crs st_make_valid
##' @importFrom dplyr "%>%" filter
##'
##' @keywords internal
map_multi_track_mp <- function(map_type,
Expand Down Expand Up @@ -53,26 +52,26 @@ map_multi_track_mp <- function(map_type,
## get worldmap
if (map_type == "default") {
if (requireNamespace("rnaturalearthhires", quietly = TRUE)) {
wm <- ne_countries(scale = 10, returnclass = "sf") %>%
st_transform(crs = prj) %>%
wm <- ne_countries(scale = 10, returnclass = "sf") |>
st_transform(crs = prj) |>
st_make_valid()
if(!silent) cat("using map scale: 10\n")
} else {
wm <- ne_countries(scale = 50, returnclass = "sf") %>%
st_transform(crs = prj) %>%
wm <- ne_countries(scale = 50, returnclass = "sf") |>
st_transform(crs = prj) |>
st_make_valid()
if(!silent) cat("using map scale: 50\n")
}

## define map region & clip land polygons
if(!is.null(obs_sf)) pts <- obs_sf
else pts <- loc_sf
land <- st_buffer(pts, dist = buffer) %>%
st_union() %>%
st_convex_hull() %>%
st_intersection(wm) %>%
st_collection_extract('POLYGON') %>%
st_sf() %>%
land <- st_buffer(pts, dist = buffer) |>
st_union() |>
st_convex_hull() |>
st_intersection(wm) |>
st_collection_extract('POLYGON') |>
st_sf() |>
st_make_valid()

p <- ggplot() +
Expand Down Expand Up @@ -132,14 +131,14 @@ map_multi_track_mp <- function(map_type,
if (all(aes$est, aes$mp)) {
p <- p +
geom_sf(
data = loc_sf %>% filter(g > 0.5),
data = loc_sf |> dplyr::filter(g > 0.5),
aes(colour = g),
size = aes$df$size[1],
stroke = 0.1,
shape = aes$df$shape[1]
) +
geom_sf(
data = loc_sf %>% filter(g <= 0.5),
data = loc_sf |> dplyr::filter(g <= 0.5),
aes(colour = g),
size = aes$df$size[1],
stroke = 0.1,
Expand Down
25 changes: 12 additions & 13 deletions R/map_single_track_base.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
##' @importFrom ggplot2 ggplot geom_sf aes ggtitle xlim ylim unit
##' @importFrom ggplot2 element_text theme scale_fill_gradientn scale_fill_manual
##' @importFrom ggplot2 element_blank scale_colour_manual scale_colour_gradientn
##' @importFrom ggplot2 element_rect coord_sf
##' @importFrom ggplot2 element_rect coord_sf element_line
##' @importFrom rnaturalearth ne_countries
##' @importFrom sf st_union st_convex_hull st_intersection st_collection_extract
##' @importFrom sf st_sf st_crs st_make_valid
##' @importFrom dplyr "%>%"
##'
##' @keywords internal
map_single_track_base <- function(map_type,
Expand All @@ -49,34 +48,34 @@ map_single_track_base <- function(map_type,

if (by.date) {
lab_dates <-
with(loc_sf, pretty(seq(min(date), max(date), l = 10), n = 5)) %>% as.Date()
with(loc_sf, pretty(seq(min(date), max(date), l = 10), n = 5)) |> as.Date()
}

prj <- st_crs(loc_sf)

## get worldmap
if (map_type == "default") {
if (requireNamespace("rnaturalearthhires", quietly = TRUE)) {
wm <- ne_countries(scale = 10, returnclass = "sf") %>%
st_transform(crs = prj) %>%
wm <- ne_countries(scale = 10, returnclass = "sf") |>
st_transform(crs = prj) |>
st_make_valid()
if(!silent) cat("using map scale: 10\n")
} else {
wm <- ne_countries(scale = 50, returnclass = "sf") %>%
st_transform(crs = prj) %>%
wm <- ne_countries(scale = 50, returnclass = "sf") |>
st_transform(crs = prj) |>
st_make_valid()
if(!silent) cat("using map scale 50\n")
}

## define map region & clip land polygons
if(!is.null(obs_sf)) pts <- obs_sf
else pts <- loc_sf
land <- suppressWarnings(st_buffer(pts, dist = buffer) %>%
st_union() %>%
st_convex_hull() %>%
st_intersection(wm) %>%
st_collection_extract('POLYGON') %>%
st_sf() %>%
land <- suppressWarnings(st_buffer(pts, dist = buffer) |>
st_union() |>
st_convex_hull() |>
st_intersection(wm) |>
st_collection_extract('POLYGON') |>
st_sf() |>
st_make_valid())

p <- ggplot() +
Expand Down
Loading

0 comments on commit b3baf49

Please sign in to comment.