I have modified the correction functions (as detailed below) to make their calculation faster (mainly by using the features of data.table). I've tried not to change the structure of the functions too much, and to make sure that all functions give the same outputs. All the current tests pass, although not all the code has been covered by the tests, so there may be some issues I've missed.
R/GenerateComment.R: the output of the function is unchanged, but the comments are generated in one go instead of using a for loop, which greatly reduces the computation time.
R/GeneralErrorsDetection.R: I adapted the code to the new GenerateComment function output, and improved readability (reduce code lines length, consistent indentation);
R/BotanicalCorrection.R: the main changes in this function are: (i) the condition argument in the GenerateComment function is now always logical (no NA); (ii) subspecies can now have more than one word (e.g. to accommodate subspecies names such as 'ssp. rattrayi' or 'var. orbiculata'); the other changes are mainly code indentation
R/DiameterCorrection.R: the main change is the use of data.table features to apply the diameter correction on a tree-by-tree basis, instead of using do.call(rbind, lapply(...)). This reduces the calculation time by about 40%. I removed some data.table warnings caused by the DBHCor column being self-referenced (which should not be a problem in our case), and revised some indentations in the code.
R/RecruitmentCorrection.R: the main change is the use of data.table package features to apply the diameter correction on a tree-by-tree basis, instead of using do.call(rbind, lapply(...)). This reduces the calculation time by about 40%. To avoid problems caused by inconsistend Diameter_TreeDataCor column class, I set its values outside the RecruitmentCorrectionByTree function (this should also reduce calculation time, and avoid having multiple similar warnings when there is no Diameter_TreeDataCor column). The test files have been changed to account for that last change.
R/StatusCorrection.R: the main change is the use of data.table package features to apply the diameter correction on a tree-by-tree basis, instead of using do.call(rbind, lapply(...)). This reduces the calculation time by about 30%. Other changes are related to code readability (indentation, line length).
R/TaperCorrection.R: the condition argument in the GenerateComment function is now always logical (no NA).
Further improvements could probably be made by first detecting problem trees before applying the correction functions only to those trees. Further improvements in computation time could also be made by moving some of the operations from tree-by-tree functions to global functions (in StatusCorrection, DiameterCorrection, RecruitmentCorrection functions).
I have modified the correction functions (as detailed below) to make their calculation faster (mainly by using the features of data.table). I've tried not to change the structure of the functions too much, and to make sure that all functions give the same outputs. All the current tests pass, although not all the code has been covered by the tests, so there may be some issues I've missed.
GenerateComment
function output, and improved readability (reduce code lines length, consistent indentation);condition
argument in theGenerateComment
function is now always logical (noNA
); (ii) subspecies can now have more than one word (e.g. to accommodate subspecies names such as 'ssp. rattrayi' or 'var. orbiculata'); the other changes are mainly code indentationdo.call(rbind, lapply(...))
. This reduces the calculation time by about 40%. I removed somedata.table
warnings caused by theDBHCor
column being self-referenced (which should not be a problem in our case), and revised some indentations in the code.data.table
package features to apply the diameter correction on a tree-by-tree basis, instead of usingdo.call(rbind, lapply(...))
. This reduces the calculation time by about 40%. To avoid problems caused by inconsistendDiameter_TreeDataCor
column class, I set its values outside theRecruitmentCorrectionByTree
function (this should also reduce calculation time, and avoid having multiple similar warnings when there is noDiameter_TreeDataCor
column). The test files have been changed to account for that last change.data.table
package features to apply the diameter correction on a tree-by-tree basis, instead of usingdo.call(rbind, lapply(...))
. This reduces the calculation time by about 30%. Other changes are related to code readability (indentation, line length).condition
argument in theGenerateComment
function is now always logical (noNA
).Further improvements could probably be made by first detecting problem trees before applying the correction functions only to those trees. Further improvements in computation time could also be made by moving some of the operations from tree-by-tree functions to global functions (in
StatusCorrection
,DiameterCorrection
,RecruitmentCorrection
functions).