Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
GuangchuangYu committed Jan 7, 2025
1 parent c8f04fb commit 021eb46
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: yulab.utils
Title: Supporting Functions for Packages Maintained by 'YuLab-SMU'
Version: 0.1.8.001
Version: 0.1.9
Authors@R: c(person("Guangchuang", "Yu", email = "guangchuangyu@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-6485-8781")))
Description: Miscellaneous functions commonly used by 'YuLab-SMU'.
Imports:
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# yulab.utils 0.1.8.001
# yulab.utils 0.1.9

+ `c2()` to concate two vectors into a 'chunked_array' object (2024-12-03, Tue)

Expand Down
19 changes: 19 additions & 0 deletions R/utilities.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
`%||%` <- function(a, b) ifelse(is.null(a), b, a)

.hi <- function(package = NULL, n=2L) {
env <- sys.parent(n)

if (!is.null(env)) {
caller <- deparse(sys.call(env))
caller <- sub("(\\w+)\\(.*", "\\1", caller)
if (is.null(package)) return(FALSE)
if (get_caller_package(caller) %in% package) return(TRUE)
}

return(FALSE)
}

get_caller_package <- function(caller) {
if (is.character) {
fn <- eval(parse(text=caller))
} else {
fn <- caller
}

return(environmentName(environment(fn)))
}

0 comments on commit 021eb46

Please sign in to comment.