-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #791 from nlmixr2/790-new-data-table
New data.table interface
- Loading branch information
Showing
10 changed files
with
104 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
.forderEnv <- new.env() | ||
.forderEnv$useBase <- FALSE | ||
|
||
|
||
.forder3 <- function(c1,c2,c3, decreasing=FALSE) { | ||
data.table::data.table(c1=c1, | ||
c2=c2, | ||
c3=c3, | ||
decreasing=decreasing, | ||
na.last=TRUE)[order(c1, c2, c3), which=TRUE] | ||
} | ||
|
||
.border3 <- function(c1,c2,c3, decreasing=FALSE) { | ||
base::order(c1, c2, c3, decreasing=decreasing, na.last=NA, method="radix") | ||
} | ||
|
||
.forder1 <- function(c1, decreasing=FALSE) { | ||
data.table::data.table(c1=c1)[order(c1, decreasing=decreasing, na.last=TRUE), which=TRUE] | ||
} | ||
|
||
.border1 <- function(c1, decreasing=FALSE) { | ||
base::order(c1, na.last=NA, decreasing=decreasing, method="radix") | ||
} | ||
|
||
.order1 <- function(c1, decreasing=FALSE) { | ||
if (.forderEnv$useBase) { | ||
.border1(c1, decreasing=decreasing) | ||
} else { | ||
.forder1(c1, decreasing=decreasing) | ||
} | ||
} | ||
|
||
.order3 <- function(c1,c2,c3, decreasing=FALSE) { | ||
if (.forderEnv$useBase) { | ||
.border3(c1,c2,c3, decreasing=decreasing) | ||
} else { | ||
.forder3(c1,c2,c3, decreasing=decreasing) | ||
} | ||
} | ||
#' Force using base order for rxode2 radix sorting | ||
#' | ||
#' @param forceBase boolean indicating if rxode2 should use R's | ||
#' [order()] for radix sorting instead of | ||
#' `data.table`'s parallel radix sorting. | ||
#' | ||
#' @return value of `forceBase` (can change if `data.table` is not | ||
#' available) | ||
#' | ||
#' @examples | ||
#' \donttest{ | ||
#' forderForceBase(TRUE) # Use base `order` for rxode2 sorts | ||
#' forderForceBase(FALSE) # Use `data.table` for rxode2 sorts | ||
#' } | ||
#' @export | ||
#' @keywords internal | ||
forderForceBase <- function(forceBase = FALSE){ | ||
if (forceBase) { | ||
.forderEnv$useBase <- forceBase | ||
} else if (requireNamespace("data.table", quietly = TRUE)) { | ||
.forderEnv$useBase <- forceBase | ||
} else { | ||
.forderEnv$useBase <- TRUE | ||
} | ||
invisible(.forderEnv$useBase) | ||
} | ||
|
||
.chin <- function(x, table) { | ||
x %in% table | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.