Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
080d82b
Moved isotope_names default and error checking to be in SIBER call no…
benjaminhlina Sep 27, 2024
ab64428
Moved tests and updated them to check extract_mu when pkg is set to S…
benjaminhlina Sep 27, 2024
856a2c0
Updated the manual regarding isotope_names
benjaminhlina Sep 27, 2024
b45f706
Trying to make niche_ellipse work with 3
benjaminhlina Sep 30, 2024
b0b813f
Update manual
benjaminhlina Sep 30, 2024
27344d8
Updated version number
benjaminhlina Oct 7, 2024
e5ed6d6
Updated version number and version name
benjaminhlina Oct 7, 2024
3ceeb4f
Fixed format spacing issue for extract_layman function
benjaminhlina Oct 7, 2024
020844e
Minor format changes
benjaminhlina Oct 7, 2024
faa4477
replaced magrittr pipes with base pipe
benjaminhlina Oct 7, 2024
2c03f8b
Minor formating changes to the code
benjaminhlina Oct 7, 2024
77efd63
replaced separate with separte_wider_delim
benjaminhlina Oct 7, 2024
e07381e
replaced magrittr pipes with base pipes
benjaminhlina Oct 7, 2024
b986081
replaced separate with separate_wider_delim
benjaminhlina Oct 7, 2024
0e9e393
Replaced T with TRUE
benjaminhlina Oct 7, 2024
64c0fe3
Update version number
benjaminhlina Oct 7, 2024
98424b2
update version number
benjaminhlina Oct 7, 2024
2363895
Minor formatting changes
benjaminhlina Oct 7, 2024
8da2cfd
Merge branch 'main' into niche_ellipse-three-isotopes
benjaminhlina Oct 7, 2024
f4fc53b
Change from isotope_a and b to isotope_names
Nov 12, 2024
b3b09ae
Added new method to create ellipse for 3 isotopes
Nov 12, 2024
72acee9
Updated tests to include isotope_names not isotope_a and b
Nov 12, 2024
7c8563b
Added tidyselect
Nov 12, 2024
51f622d
Added tidyselect
Nov 12, 2024
907f17a
Fixed typo in documents
Nov 12, 2024
0532baa
added tidyselect
Nov 12, 2024
6c614ab
Fixed df_ to dat_
Nov 12, 2024
4787672
Added new variables
Nov 12, 2024
87afefa
Update version number to 0.3.3
Nov 12, 2024
62c96c5
Update package version
Nov 12, 2024
c7aba11
Export isotope_pairs
Dec 18, 2024
70a8693
create isotope_pairs function
Dec 18, 2024
f73c4dc
Updated documentatyion
Dec 18, 2024
5df73d1
Create vignettes on three isotopes
yourpresidentuniversal Dec 18, 2024
9ff4155
renamed vigignettes
yourpresidentuniversal Dec 18, 2024
5728eaa
replace with create_iso_pairs
yourpresidentuniversal Dec 18, 2024
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
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: nichetools
Type: Package
Title: Complementary Package to 'nicheROVER' and 'SIBER'
Version: 0.3.2
Version: 0.3.3
Authors@R:
c(person(given = "Benjamin L.",
family = "Hlina",
Expand All @@ -27,7 +27,8 @@ Imports:
rlang,
SIBER,
tibble,
tidyr
tidyr,
tidyselect
License: CC0
Encoding: UTF-8
LazyData: true
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(create_comparisons)
export(create_isotope_pairs)
export(extract_group_metrics)
export(extract_layman)
export(extract_mu)
Expand All @@ -15,6 +16,7 @@ import(ellipse)
import(purrr)
import(tibble)
import(tidyr)
import(tidyselect)
importFrom(lifecycle,deprecated)
importFrom(nicheROVER,niche.size)
importFrom(rlang,":=")
Expand Down
55 changes: 55 additions & 0 deletions R/create_isotope_pairs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#' Create isotope pairs
#'
#' @param isotope_n number of isotopes
#' @param isotope_names names of isotopes
#'
#' @export

create_isotope_pairs <- function(isotope_n = NULL,
isotope_names = NULL) {

# create name vector that will be used to id isotopes.
if (is.null(isotope_n)) {
isotope_n <- 3

Check warning on line 13 in R/create_isotope_pairs.R

View check run for this annotation

Codecov / codecov/patch

R/create_isotope_pairs.R#L12-L13

Added lines #L12 - L13 were not covered by tests
}
if (!is.numeric(isotope_n) || !(isotope_n %in% c(3))) {
cli::cli_abort("Argument 'isotope_n' must 3.")

Check warning on line 16 in R/create_isotope_pairs.R

View check run for this annotation

Codecov / codecov/patch

R/create_isotope_pairs.R#L15-L16

Added lines #L15 - L16 were not covered by tests
}

if (isotope_n == 3) {
if (is.null(isotope_names)) {
isotope_names <- c("d13c", "d15n", "d34s")

Check warning on line 21 in R/create_isotope_pairs.R

View check run for this annotation

Codecov / codecov/patch

R/create_isotope_pairs.R#L19-L21

Added lines #L19 - L21 were not covered by tests
}
}
if (!is.character(isotope_names)) {
cli::cli_abort("Argument 'isotope_names' must be a character.")

Check warning on line 25 in R/create_isotope_pairs.R

View check run for this annotation

Codecov / codecov/patch

R/create_isotope_pairs.R#L24-L25

Added lines #L24 - L25 were not covered by tests
}

# ---- create every combo in table ----
iso_combo <- tidyr::expand_grid(iso_a = isotope_names,
iso_b = isotope_names) |>
dplyr::filter(iso_a < iso_b) |>
dplyr::mutate(
iso_ab = paste(iso_a, iso_b, sep = "_")
) |>
dplyr::distinct(iso_ab) |>
tidyr::separate_wider_delim(iso_ab, names = c("iso_a", "iso_b"),
delim = "_")

Check warning on line 37 in R/create_isotope_pairs.R

View check run for this annotation

Codecov / codecov/patch

R/create_isotope_pairs.R#L29-L37

Added lines #L29 - L37 were not covered by tests

# created id column
iso_combo$id <- 1:nrow(iso_combo)

Check warning on line 40 in R/create_isotope_pairs.R

View check run for this annotation

Codecov / codecov/patch

R/create_isotope_pairs.R#L40

Added line #L40 was not covered by tests

# pivot longer to create vector that can be used to filter combinations
split_iso <- split(iso_combo, iso_combo$id) |>
purrr::map(~ tidyr::pivot_longer(.x, cols = -id,
values_to = "iso_name") |>
dplyr::mutate(
iso_name = factor(iso_name, level = c("d34s",
"d13c",
"d15n"))
) |>
dplyr::arrange(iso_name) |>
getElement("iso_name")
)
return(split_iso)

Check warning on line 54 in R/create_isotope_pairs.R

View check run for this annotation

Codecov / codecov/patch

R/create_isotope_pairs.R#L43-L54

Added lines #L43 - L54 were not covered by tests
}
2 changes: 1 addition & 1 deletion R/extract_group_metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extract_group_metrics <- function(data = NULL,


# set data formatt
if(is.null(data_format)) {
if (is.null(data_format)) {
data_format <- "long"
}

Expand Down
4 changes: 2 additions & 2 deletions R/extract_layman.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ extract_layman <- function(data,
element_y <- "N"
}

if(type %in% "bay") {
if (type %in% "bay") {

df_layman <- data |>
purrr::map(~ as_tibble(.x)) |>
Expand Down Expand Up @@ -224,7 +224,7 @@ extract_layman <- function(data,

return(df_layman)
}
if (data_format %in% "wide"){
if (data_format %in% "wide") {
return(df_layman)
}
}
Expand Down
47 changes: 22 additions & 25 deletions R/extract_mu.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#' you're using. Defaults to `"nicheROVER"`.
#' Alternatively the user can supply the argument with `"SIBER"`.
#' @param isotope_names is a vector of `character` string used change the column name
#' of isotopes used in the analysis. Defaults to `c("d13c", "d15n")`.
#' of isotopes used in the analysis. Defaults to `c("d13c", "d15n")`. To be used when
#' `pkg` is set to `"SIBER"`.
#' @param data_format a `character` string that decides whether the returned object is
#' in long or wide format. Default is `"long"`, with the alternative supplied
#' being `"wide"`.
Expand All @@ -27,6 +28,7 @@
#' from [{SIBER}](https://CRAN.R-project.org/package=SIBER).
#' The third and fourth columns contains the actual names of the communities
#' and groups the user is working with (e.g., `"region"`, `"common_name"`).
#' To be used when `pkg` is set to `"SIBER"`.
#'
#' @return Returns a `tibble` of extracted estimates of \eqn{\mu} created by the
#' function `niw.post()` or `siberMVN()` in the packages
Expand Down Expand Up @@ -98,28 +100,9 @@ extract_mu <- function(data,
'nicheROVER' or 'SIBER'.")
}

# defaults of isotpoe a and b
if (is.null(isotope_names)) {
isotope_names <- c("d13c", "d15n")
}

# Check if isotope_names is a character vector
if (!is.vector(isotope_names) || !is.character(isotope_names)) {
cli::cli_abort("The supplied argument for 'isotope_names' must be a vector of characters.")
}

# Check if isotope_names has exactly 2 elements
if (length(isotope_names) != 2) {
cli::cli_abort("The 'isotope_names' vector must have exactly 2 elements, representing isotope_a and isotope_b.")
}

# # Check if isotope_b is character
# if (!is.character(isotope_b)) {
# cli::cli_abort("The supplied argument for 'isotope_b' must be a character.")
# }


# sett data formatt
# sett data format
if (is.null(data_format)) {
data_format <- "long"
}
Expand Down Expand Up @@ -191,6 +174,20 @@ extract_mu <- function(data,
}


# defaults of isotpoe a and b
if (is.null(isotope_names)) {
isotope_names <- c("d13c", "d15n")
}

# Check if isotope_names is a character vector
if (!is.vector(isotope_names) || !is.character(isotope_names)) {
cli::cli_abort("The supplied argument for 'isotope_names' must be a vector of characters.")
}

# Check if isotope_names has exactly 2 elements
if (length(isotope_names) != 2) {
cli::cli_abort("'isotope_names' must have exactly 2 elements, representing isotope_a and isotope_b")
}
id_isotope <- isotope_names


Expand All @@ -199,7 +196,7 @@ extract_mu <- function(data,
df <- .x[, 5:6] |>
t() |>
as.numeric() |>
matrix(ncol = 1, byrow = T) |>
matrix(ncol = 1, byrow = TRUE) |>
as.data.frame() |>
tibble::as_tibble()

Expand All @@ -219,12 +216,12 @@ extract_mu <- function(data,
dplyr::rename(
mu_est = V1
) |>
dplyr::select(metric, sample_name,sample_number, isotope, mu_est) %>%
dplyr::select(metric, sample_name,sample_number, isotope, mu_est) |>
separate_wider_delim(sample_name, cols_remove = FALSE,
delim = ".", names = c("community",
"group")) %>%
"group")) |>
left_join(community_df, by = c("community",
"group")) %>%
"group")) |>
dplyr::select(metric:sample_number, community_name,
group_name, isotope, mu_est)

Expand Down
10 changes: 5 additions & 5 deletions R/extract_overlap.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ extract_overlap <- function(data,
}

# set name_a null
if (is.null(name_a)){
if (is.null(name_a)) {
name_a <- "sample_name_a"
}
# set name_b null
if (is.null(name_b)){
if (is.null(name_b)) {
name_b <- "sample_name_b"
}

Expand All @@ -60,12 +60,12 @@ extract_overlap <- function(data,
tidyr::pivot_longer(cols = -c(id, species_a),
names_to = "species_b",
values_to = "niche_overlap") |>
tidyr::separate(species_b, into = c("species_b", "sample_number"),
sep = "\\.") |>
tidyr::separate_wider_delim(species_b, names = c("species_b", "sample_number"),
delim = ".") |>
dplyr::rename(
{{name_a}} := species_a,
{{name_b}} := species_b
) %>%
) |>
dplyr::mutate(
niche_overlap_perc = niche_overlap * 100
)
Expand Down
11 changes: 6 additions & 5 deletions R/extract_sigma.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ extract_sigma <- function(data,
dplyr::bind_rows(.id = "isotope_num") |>
dplyr::mutate(
id = 1
) %>%
) |>
tidyr::pivot_longer(-id)

isotope_length <- unique(isotope_number$value)
Expand Down Expand Up @@ -145,7 +145,7 @@ extract_sigma <- function(data,
dplyr::bind_rows(.id = "isotope_num") |>
dplyr::mutate(
id = 1
) %>%
) |>
tidyr::pivot_longer(-id)

isotope_length <- unique(isotope_number$value)
Expand All @@ -171,8 +171,9 @@ extract_sigma <- function(data,
names_to = "isotope",
values_to = "post_sample"
) |>
tidyr::separate(isotope, into = c("isotope", "sample_number"),
sep = "\\.")
tidyr::separate_wider_delim(isotope, names = c("isotope", "sample_number"),

delim = ".")



Expand Down Expand Up @@ -220,7 +221,7 @@ extract_sigma <- function(data,
df <- .x[, 1:4] |>
t() |>
as.numeric() |>
matrix(ncol = 2, byrow = T) |>
matrix(ncol = 2, byrow = TRUE) |>
as.data.frame() |>
tibble::as_tibble()

Expand Down
Loading