Skip to content

Commit

Permalink
Replaced setDT(copy()) by data.table()
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurBailly committed Oct 21, 2024
1 parent 0f94827 commit 5b92f52
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions R/getTaxonomy.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ getTaxonomy <- function(genus, findOrder = FALSE) {
################## 1. Retrieve the Family

# Load taxonomical data (sourced from Angiosperm Phylogeny Website, http://www.mobot.org/MOBOT/research/APweb/)
genusFamily <- setDT(copy(BIOMASS::genusFamily))
genusFamily <- data.table(BIOMASS::genusFamily)
setkey(genusFamily, genus)

# Create ids
Expand All @@ -48,7 +48,7 @@ getTaxonomy <- function(genus, findOrder = FALSE) {
################## 2. Retrieve the Order

if (findOrder == TRUE) {
apgFamilies <- setDT(copy(BIOMASS::apgFamilies))
apgFamilies <- data.table(BIOMASS::apgFamilies)

genusFam <- merge(genusFam, apgFamilies, by.x = "family", by.y = "famAPG", all.x = TRUE)
genusFam <- genusFam[, .(id, inputGenus, family, order)]
Expand Down
10 changes: 5 additions & 5 deletions R/getWoodDensity.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ if (getRversion() >= "2.15.1") {
#' }
#' @seealso [wdData], [sd_10]
#' @keywords Wood density
#' @importFrom data.table data.table := setDF setDT setkey copy chmatch %chin%
#' @importFrom data.table data.table := setDF setDT setkey chmatch %chin%
#'
getWoodDensity <- function(genus, species, stand = NULL, family = NULL, region = "World",
addWoodDensityData = NULL, verbose = TRUE) {
Expand Down Expand Up @@ -148,11 +148,11 @@ getWoodDensity <- function(genus, species, stand = NULL, family = NULL, region =
# Data processing ---------------------------------------------------------

# Load global wood density database downloaded from http://datadryad.org/handle/10255/dryad.235
wdData <- setDT(copy(BIOMASS::wdData))
wdData <- data.table(BIOMASS::wdData)

# Load the mean standard deviation observed at the species, Genus or Family level
# in the Dryad dataset when at least 10 individuals are considered
sd_10 <- setDT(copy(BIOMASS::sd_10))
sd_10 <- data.table(BIOMASS::sd_10)
sd_tot <- sd(wdData$wd)

Region <- tolower(region)
Expand All @@ -175,7 +175,7 @@ getWoodDensity <- function(genus, species, stand = NULL, family = NULL, region =
if (!is.null(addWoodDensityData)) {
setDT(addWoodDensityData)
if (!("family" %in% names(addWoodDensityData))) {
genusFamily <- setDT(copy(BIOMASS::genusFamily))
genusFamily <- data.table(BIOMASS::genusFamily)
addWoodDensityData[genusFamily, on = "genus", family := i.family]
}
addWoodDensityData <- addWoodDensityData[!is.na(wd), ]
Expand All @@ -195,7 +195,7 @@ getWoodDensity <- function(genus, species, stand = NULL, family = NULL, region =
inputData[, family := as.character(family)]
} else {
if (!exists("genusFamily", inherits = FALSE)) {
genusFamily <- setDT(copy(BIOMASS::genusFamily))
genusFamily <- data.table(BIOMASS::genusFamily)
}
inputData[genusFamily, on = "genus", family := i.family]
}
Expand Down
2 changes: 1 addition & 1 deletion data-raw/apgfamily.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ setDF(apgFamilies)
usethis::use_data(apgFamilies, compress = "xz", overwrite = FALSE)


apgFamiliesOrg <- setDT(copy(BIOMASS::apgFamilies))
apgFamiliesOrg <- data.table(BIOMASS::apgFamilies)
apgFamiliesOrg <- apgFamiliesOrg[base::order(order)]
apgFamilies <- apgFamilies[base::order(order)]

Expand Down
2 changes: 1 addition & 1 deletion data-raw/genusFamily.R
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ usethis::use_data(genusFamily, compress = "xz")


genusFamily <- genusFamily[base::order(family)]
genusFamilyOrg <- setDT(copy(BIOMASS::genusFamily))
genusFamilyOrg <- data.table(BIOMASS::genusFamily)
genusFamilyOrg <- genusFamilyOrg[base::order(family)]

result <- merge(genusFamilyOrg, genusFamily, all = T, by = "genus")
Expand Down
2 changes: 1 addition & 1 deletion data-raw/sd_10.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require(data.table)
# )
# data_wd[, c("genus", "species") := tstrsplit(Binomial, " ", keep = 1:2)]

data_wd <- setDT(copy(BIOMASS::wdData))
data_wd <- data.table(BIOMASS::wdData)


species <- data_wd[, .(family, genus, wd, .N), by = species][N >= 10][, .(sd = sd(wd)), by = species][, mean(sd)]
Expand Down

0 comments on commit 5b92f52

Please sign in to comment.