Skip to content

Commit 2dec395

Browse files
authored
Fix most significant lints (#86)
* Use xor() where possible * Mark fixed pattern detection as such * Use anyNA() where possible * Use %||% where possible
1 parent ee995de commit 2dec395

File tree

6 files changed

+19
-24
lines changed

6 files changed

+19
-24
lines changed

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: fundiversity
22
Title: Easy Computation of Functional Diversity Indices
33
Version: 1.1.1
4-
Authors@R:
4+
Authors@R:
55
c(
66
person("Matthias", "Grenié",
77
email = "matthias.grenie@gmail.com",
@@ -24,8 +24,8 @@ Encoding: UTF-8
2424
LazyData: true
2525
Roxygen: list(markdown = TRUE)
2626
RoxygenNote: 7.3.2
27-
Depends:
28-
R (>= 2.10)
27+
Depends:
28+
R (>= 3.2.0)
2929
Imports:
3030
future.apply,
3131
geometry,

R/fd_feve.R

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
#' @export
3535
fd_feve <- function(traits = NULL, sp_com, dist_matrix = NULL) {
3636

37-
if ((!is.null(traits) && !is.null(dist_matrix)) ||
38-
(is.null(traits) && is.null(dist_matrix))) {
37+
if (!xor(is.null(traits), is.null(dist_matrix))) {
3938
stop(
4039
"Please provide either a trait dataset or a dissimilarity matrix",
4140
call. = FALSE
@@ -71,11 +70,7 @@ fd_feve <- function(traits = NULL, sp_com, dist_matrix = NULL) {
7170
)
7271
}
7372

74-
if (is.null(rownames(sp_com))) {
75-
76-
rownames(sp_com) <- paste0("s", seq_len(nrow(sp_com)))
77-
78-
}
73+
rownames(sp_com) <- rownames(sp_com) %||% paste0("s", seq_len(nrow(sp_com)))
7974

8075
# Standardize abundance per site
8176
site_abundances <- rowSums(sp_com, na.rm = TRUE)

R/fd_fric_intersect.R

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,8 @@ fd_fric_intersect <- function(traits, sp_com, stand = FALSE) {
8888

8989
}
9090

91-
if (is.null(rownames(sp_com))) {
91+
rownames(sp_com) <- rownames(sp_com) %||% paste0("s", seq_len(nrow(sp_com)))
9292

93-
rownames(sp_com) <- paste0("s", seq_len(nrow(sp_com)))
94-
95-
}
9693

9794
max_range <- 1
9895

@@ -145,7 +142,7 @@ fd_fric_intersect <- function(traits, sp_com, stand = FALSE) {
145142
}
146143
}, future.globals = FALSE)
147144

148-
if (any(is.na(fric_intersect))) {
145+
if (anyNA(fric_intersect)) {
149146
warning(
150147
"Some sites had less species than traits so returned FRic_intersect ",
151148
"is 'NA'",

R/fd_raoq.R

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
#' @export
3535
fd_raoq <- function(traits = NULL, sp_com, dist_matrix = NULL) {
3636

37-
if ((!is.null(traits) && !is.null(dist_matrix)) ||
38-
(is.null(traits) && is.null(dist_matrix))) {
37+
if (!xor(is.null(traits), is.null(dist_matrix))) {
3938
stop(
4039
"Please provide either a trait dataset or a dissimilarity matrix",
4140
call. = FALSE
@@ -79,11 +78,7 @@ fd_raoq <- function(traits = NULL, sp_com, dist_matrix = NULL) {
7978

8079
}
8180

82-
if (is.null(rownames(sp_com))) {
83-
84-
rownames(sp_com) <- paste0("s", seq_len(nrow(sp_com)))
85-
86-
}
81+
rownames(sp_com) <- rownames(sp_com) %||% paste0("s", seq_len(nrow(sp_com)))
8782

8883
# Standardize abundance per site
8984
site_abundances <- rowSums(sp_com, na.rm = TRUE)

R/utils.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This can be deleted in favour of base R version if we ever start depending
2+
# on R (>= 4.4.0)
3+
`%||%` <- function(x, y) {
4+
if (is.null(x)) {
5+
y
6+
} else {
7+
x
8+
}
9+
}

vignettes/_fundiversity_2-performance.Rmd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,7 @@ all_bench_sites <- list(fric = bench_sites_fric,
386386
raoq = bench_sites_raoq,
387387
feve = bench_sites_feve) %>%
388388
bind_rows(.id = "fd_index") %>%
389-
mutate(n_sites = gsub("sites", "", expr) %>%
390-
as.numeric())
389+
mutate(n_sites = as.numeric(gsub("sites", "", expr, fixed = TRUE)))
391390

392391
all_bench_sites %>%
393392
ggplot(aes(n_sites, time * 1e-9, color = fd_index)) +

0 commit comments

Comments
 (0)