yulab.utils/0000755000176200001440000000000014746344222012535 5ustar liggesusersyulab.utils/MD50000644000176200001440000000566314746344222013057 0ustar liggesusersbdbc33686bbff396223a63f41200cd00 *DESCRIPTION be784f9d486c3b3f632918b731441edd *NAMESPACE ebafcb7aa06a2ae6e92e851ac2794f9e *NEWS.md 007e3de7a11b71539e2d8617ebc295c5 *R/bib-ggtree.R 53a06eaae05f939981d43ffbe9b636c8 *R/bib-knownledge.R 8c817a90acb8deb76024a36d5662c824 *R/biorxiv.R 09a18d0b822d2e29ca10ba3e76fb7485 *R/cache.R 95effca842167b8d4ab1d11056e3e84e *R/combinations.R 664948f3ab8aa48e35c8dd268bcdf822 *R/concat.r 135705b0f129acd7f0418127a17e8994 *R/download.R 5e45a091afcc9573f8c2eef871845044 *R/file.R a88f332cc523f835302372eb330808c1 *R/install_zip.R 29332963a97b933d165880d14b5a926f *R/list.R c9d9db73e55f3aadfa2a3cde09cd51c6 *R/matrix-utils.R e703f7689d1b0a0d7ea2dcaed9fa1038 *R/os.R bc5a9393353846510cf4f532137aa7d0 *R/pkg-utils.R 522473cababc10ee439a582555d821cb *R/regexpr.R 0db1a99ecdc6501760d342d82da783a8 *R/scale.R 8b2467b550b0debf2161c3ffa984f73c *R/scihub-dl.R 5b32966c3e9170d5ab3207e9ea07211a *R/str-utils.R a33656388df140e42f096042e4d94c4f *R/sudo-install.R ee2efad4700779e729634304bc862ee5 *R/utilities.R 2bcf5d590c3a9828af87f6ebcf4113a6 *R/yulab-msg.R da7bac5323d313dfbcdb38f8fbf613f0 *R/yulab-utils-package.R 81128a8e2c6dac0484310aefb614e6c3 *R/zzz.R e102b8ef2ffb9aafef52223a22e88753 *inst/prototype/GEO.r fe6013508f10ad5584815759267861f0 *inst/prototype/sra.r d611cc86140e279caf3e3acb788b6153 *man/c2.Rd 438fff93f806ab18e9db99060cbabb1b *man/check_pkg.Rd 740f5276df44ad1e6766f7a37fe1d21a *man/combinations.Rd db93bb4ab3c70d03ce07c3a35f237cdd *man/cran-bioc-pkg.Rd aeaacad247b828ca4591480b2015c198 *man/exec.Rd e729417aa83b01b31ac177ed6f6c3a14 *man/get_dependencies.Rd feeda9894ca366d3cecd321a26b1c757 *man/get_fun_from_pkg.Rd 4037c412514457e4aa46f4ae2e87a25d *man/github-pkg.Rd e0532e636b9a265f753170bf7ad77605 *man/has_internet.Rd dfbc4e67550a8ff93dd167f828333c0a *man/install_zip.Rd 27416a715194cdda190410318907fcb7 *man/install_zip_gh.Rd f1fb5a178766a681c0ee36d3ee16f50f *man/is.installed.Rd 7429eb4c6b9f62553ecae5e16edc4824 *man/ls2df.Rd 6ad39ca2459889f1cdd3f10b50cca2b1 *man/mat2df.Rd 035dbcab8d8db17527a76278426722ca *man/mat2list.Rd 5de5c1a676be17dc7fbe1de44a430b38 *man/mypkg.Rd 350771e856ec3d6a012327e9f9a7661c *man/o.Rd e101a49107b31f0d3bedef24de40e2a5 *man/packageTitle.Rd 8317241089ca88b826c9fab73d536d8e *man/pload.Rd 340d383c001465de8a3773b6cd1db10b *man/rbindlist.Rd 0e20524bfebe8e2ef91eea11dbb62ccb *man/read.cb.Rd 94015f38ecbf2eeb9f295345d938b702 *man/regexpr-style.Rd e4439fe352c1817015d3bc28bd4f5abf *man/scale_range.Rd 7ca4626445edad5c55b084c9a360cff2 *man/scihub-dl.Rd 376e2961dcdfc973c2449512a05eb2a3 *man/show_in_excel.Rd ea0c0f3acb8187602161ff2a7bc5d1ac *man/str-detect.Rd 0ee359877a2bc4bd14136104fd61d24f *man/str-extract.Rd be70aa2c7a2cc288386c27b41a1d122a *man/str-starts-ends.Rd 3aade7406ca5eaadbc07b0c5679b063b *man/str_wrap.Rd 4ced4ba5fc9eca943c92574732a1b205 *man/yread.Rd 0c88c99a76427c4980cf90320e9c3057 *man/yulab-cache.Rd eedc7b6680597a4df3d869fe84f9ca5c *man/yulab.utils-package.Rd 376b3e7335587d2531cd9360557fcc9d *man/yulab_msg.Rd yulab.utils/R/0000755000176200001440000000000014723463462012741 5ustar liggesusersyulab.utils/R/cache.R0000644000176200001440000000547114543172714014133 0ustar liggesusers##' @rdname yulab-cache ##' @export initial_cache <- function() { pos <- 1 envir <- as.environment(pos) assign(".yulabCache", new.env(), envir = envir) } ##' @rdname yulab-cache ##' @export get_cache <- function() { if (!exists(".yulabCache", envir = .GlobalEnv)) { initial_cache() } get(".yulabCache", envir = .GlobalEnv) } ##' @rdname yulab-cache ##' @export rm_cache <- function() { if (exists(".yulabCache", envir = .GlobalEnv)) { rm(".yulabCache", envir = .GlobalEnv) } } ##' @rdname yulab-cache ##' @export initial_cache_item <- function(item) { env <- get_cache() assign(item, list(), envir = env) } ##' @rdname yulab-cache ##' @export get_cache_item <- function(item) { env <- get_cache() if (!exists(item, envir = env)) { initial_cache_item(item) } get(item, envir = env, inherits = FALSE) } ##' @rdname yulab-cache ##' @export rm_cache_item <- function(item) { env <- get_cache() if (exists(item, envir = env)) { rm(list = item, envir = env) } } ##' cache intermediate data ##' ##' Yulab provides a set of utilities to cache intermediate data, ##' including initialize the cached item, update cached item and rmove the cached item, etc. ##' ##' @rdname yulab-cache ##' @param item the name of the cached item ##' @param elements elements to be cached in the item ##' @return return the cache environment, item or selected elements, depends on the functions. ##' @importFrom utils modifyList ##' @export ##' @examples ##' \dontrun{ ##' slow_fib <- function(x) { ##' if (x < 2) return(1) ##' slow_fib(x-2) + slow_fib(x-1) ##' } ##' ##' fast_fib <- function(x) { ##' if (x < 2) return(1) ##' res <- get_cache_element('fibonacci', as.character(x)) ##' if (!is.null(res)) { ##' return(res) ##' } ##' res <- fast_fib(x-2) + fast_fib(x-1) ##' e <- list() ##' e[[as.character(x)]] <- res ##' update_cache_item('fibonacci', e) ##' return(res) ##' } ##' ##' system.time(slow_fib(30)) ##' system.time(fast_fib(30)) ##' ##' } update_cache_item <- function(item, elements) { msg <- "new elements should be stored as a named list" if (!inherits(elements, 'list')) { stop(msg) } if (is.null(names(elements))) { stop(msg) } if(any(names(elements) == "")) { stop(msg) } env <- get_cache() res <- get_cache_item(item) res <- modifyList(res, elements) assign(item, res, envir = env) } ##' @rdname yulab-cache ##' @export get_cache_element <- function(item, elements) { x <- get_cache_item(item) n <- length(elements) if (n == 1) return(x[[elements]]) return(x[elements]) } yulab.utils/R/pkg-utils.R0000644000176200001440000001535514712620134015001 0ustar liggesusers##' loading a package ##' ##' The function use 'library()' to load the package. ##' If the package is not installed, the function will try to install it before loading it. ##' @title pload ##' @param package package name ##' @param action function used to install package. ##' If 'action = "auto"', it will try to use 'BiocManager::install()' if it is available. ##' @return the selected package loaded to the R session ##' @importFrom rlang as_name ##' @importFrom rlang enquo ##' @importFrom rlang check_installed ##' @importFrom cli cli_h2 ##' @importFrom utils getFromNamespace ##' @export ##' @author Guangchuang Yu pload <- function(package, action = "auto") { pkg <- as_name(enquo(package)) if (action == "auto") { if (is.installed("BiocManager")) { install <- getFromNamespace("install", "BiocManager") action <- function(package, ask=FALSE, update=FALSE, ...) { install(package, ask=ask, update = update, ...) } } else { action <- NULL } } check_installed(pkg, action = action) pkg <- sub("\\w+/", "", pkg) # for github pkg: repo/pkg cli::cli_h2(sprintf("loading the package: %s", pkg)) library(pkg, character.only = TRUE) } ##' get reverse dependencies ##' ##' ##' @title get_dependencies ##' @param pkg package name ##' @param repo 'CRAN' and/or 'BioC' ##' @return reverse dependencies ## @importFrom BiocInstaller biocinstallRepos ##' @importFrom tools package_dependencies ##' @export ##' @author Guangchuang Yu get_dependencies <- function(pkg, repo=c("CRAN", "BioC")) { rp <- get_repo(repo) db <- utils::available.packages(repo=rp) tools::package_dependencies(pkg, db=db, reverse=TRUE) } get_repo <- function(repo = c("CRAN", "BioC")) { rp <- c() if ('CRAN' %in% repo) { cran <- getOption("repos")["CRAN"] if (is.null(cran)) { cran <- "http://cloud.r-project.org/" } rp <- c(rp, cran) } if ('BioC' %in% repo) { bioc <- getOption("BioC_mirror") if (is.null(bioc)) { bioc <- "https://mirrors.tuna.tsinghua.edu.cn/bioconductor/" } rp <- c(rp, bioc) } ## options(repos = biocinstallRepos()) sub("/$", "", rp) } ##' Extract package title ##' ##' ##' @title packageTitle ##' @param pkg package name ##' @param repo 'CRAN' and/or 'BioC' ##' @return reverse dependencies ##' @importFrom utils packageDescription ##' @export ##' @author Guangchuang Yu packageTitle <- function(pkg, repo='CRAN') { title <- tryCatch(packageDescription(pkg)$Title, error=function(e) NULL) if (is.null(title)) { repo_url <- get_repo(repo) if (repo == "CRAN") { url <- sprintf("%s/package=%s", repo_url, pkg) } else { bioc_type <- c("bioc", "workflows", "data/annotation", "data/experiment") url <- sprintf("%s/packages/release/%s/html/%s.html", repo_url, bioc_type, pkg) } ## x <- tryCatch(readLines(url), error = function(e) NULL) ## if (is.null(x)) return("") for (u in url) { x <- tryCatch(yread(u), error = function(e) NULL) if (!is.null(x)) { break() } } if (is.null(x)) { return(NA) } i <- grep('^\\s*

', x) if (grepl("

$", x[i])) { xx <- x[i] } else { j <- grep('$', x) xx <- paste(x[i:j], collapse=" ") } title <- gsub('$', '', gsub('\\s*

', '', xx)) } sub("^\\w+\\s*:\\s*", "", gsub("\n", " ", title)) } ##' Check whether the input packages are installed ##' ##' This function check whether the input packages are installed ##' @title is.installed ##' @param packages package names ##' @return logical vector ##' @export ##' @examples ##' is.installed(c("dplyr", "ggplot2")) ##' @author Guangchuang Yu is.installed <- function(packages) { vapply(packages, function(package) { system.file(package=package) != "" }, logical(1)) } ##' Check whether the input packages are installed ##' ##' This function check whether the input packages are installed. If not, it asks the user whether to install the missing packages. ##' @title check_pkg ##' @param pkg package names ##' @param reason the reason to check the pkg. If NULL, it will set the reason to the parent call. ##' @param ... additional parameters that passed to `rlang::check_installed()` ##' @return see also [check_installed][rlang::check_installed] ##' @export ##' @importFrom rlang check_installed ##' @author Guangchuang Yu check_pkg <- function(pkg, reason=NULL, ...) { # v1 # # if (!is.installed(pkg)) { # msg <- sprintf("%s is required, please install it first", pkg) # stop(msg) # } if (is.null(reason)) { call <- sys.call(1L) reason <- sprintf("for %s()", as.character(call)[1]) } rlang::check_installed(pkg, reason, ...) } ##' load function from package ##' ##' ##' @title get_fun_from_pkg ##' @param pkg package ##' @param fun function ##' @return function ##' @export ##' @examples ##' get_fun_from_pkg('utils', 'zip') ##' @author Guangchuang Yu get_fun_from_pkg <- function(pkg, fun) { ## v1 ## ## requireNamespace(pkg) ## eval(parse(text=paste0(pkg, "::", fun))) ## v2 ## ## require(pkg, character.only = TRUE) ## eval(parse(text = fun)) # check_pkg(pkg) utils::getFromNamespace(fun, pkg) } ##' print md text of package with link to homepage (CRAN or Bioconductor) ##' ##' ##' @rdname cran-bioc-pkg ##' @param pkg package name ##' @return md text string ##' @export ##' @author Guangchuang Yu CRANpkg <- function(pkg) { cran <- "https://CRAN.R-project.org/package" fmt <- "[%s](%s=%s)" sprintf(fmt, pkgfmt(pkg), cran, pkg) } ##' @rdname cran-bioc-pkg ##' @export Biocpkg <- function(pkg) { sprintf("[%s](http://bioconductor.org/packages/%s)", pkgfmt(pkg), pkg) } ##' print md text of package with link to github repo ##' ##' ##' @rdname github-pkg ##' @param user github user ##' @param pkg package name ##' @return md text string ##' @export ##' @author Guangchuang Yu Githubpkg <- function(user, pkg) { gh <- "https://github.com" fmt <- "[%s](%s/%s/%s)" sprintf(fmt, pkgfmt(pkg), gh, user, pkg) } ##' print md text of link to a pakcage ##' ##' ##' @title mypkg ##' @param pkg package name ##' @param url package url ##' @return md text string ##' @export ##' @author Guangchuang Yu mypkg <- function(pkg, url) { fmt <- "[%s](%s)" sprintf(fmt, pkgfmt(pkg), url) } pkgfmt <- function(pkg) { fmt <- getOption('yulab.utils_pkgfmt', default="%s") sprintf(fmt, pkg) } yulab.utils/R/download.R0000644000176200001440000000045114660652063014670 0ustar liggesusersmydownload <- function(url, destfile) { if (is.installed('httr2')) { req <- httr2::request(url) |> httr2::req_progress() req |> httr2::req_perform(path = destfile) } else { download.file(url = url, destfile = destfile) } } yulab.utils/R/os.R0000644000176200001440000000270014663004004013466 0ustar liggesusers##' run system command ##' ##' ##' @title exec ##' @param command system command to run ##' @return An `exec` instance that stores system command outputs ##' @export ##' @author Guangchuang Yu exec <- function(command) { res <- system(command, intern=TRUE) structure(res, class = "exec") } ##' @method print exec ##' @export print.exec <- function(x, ...) { cat(x, sep='\n') } has_bin <- function(bin) { os <- which_os() which <- "which" if (os == "Windows") { which <- "where" } command <- sprintf("%s %s", which, bin) exit_code <- system(command, ignore.stdout = TRUE, ignore.stderr = TRUE) return(exit_code == 0) } ##' test for internect connection via reading lines from a URL ##' ##' ##' @title has_internet ##' @param site URL to test connection ##' @return logical value ##' @export ##' @author Guangchuang Yu has_internet <- function(site = "https://www.baidu.com/") { ret <- tryCatch( suppressWarnings(readLines(site, n = 1)), error = function(e) NULL ) return(!is.null(ret)) } which_os <- function() { Sys.info()[1] } user_dir <- function(appname = NULL, appauthor = NULL, ...) { dir <- rappdirs::user_data_dir( appname = appname, appauthor=appauthor, ...) if (!dir.exists(dir)) dir.create(dir, recursive = TRUE) return(dir) } yulab.utils/R/combinations.R0000644000176200001440000000050014471060615015535 0ustar liggesusers#' all possible combinations of n sets #' #' @title combinations #' @param n number of sets #' @return a list of all combinations #' @importFrom utils combn #' @export combinations <- function(n){ l <- lapply(seq_len(n), function(x){ m <- combn(n,x) mat2list(m) }) unlist(l, recursive = F) } yulab.utils/R/list.R0000644000176200001440000000147614474263164014047 0ustar liggesusers##' rbind a list ##' ##' ##' @title rbindlist ##' @param x a list that have similar elements that can be rbind to a data.frame ##' @return data.frame ##' @author Guangchuang Yu ##' @export rbindlist <- function(x) { do.call('rbind', x) } ##' Convert a list of vector to a data.frame object. ##' ##' ##' @title Convert a list of vector (e.g, gene IDs) to a data.frame object ##' @param inputList A list of vector ##' @return a data.frame object. ##' @export ls2df <- function(inputList) { # ldf <- lapply(1:length(inputList), function(i) { ldf <- lapply(seq_len(length(inputList)), function(i) { data.frame(category=rep(names(inputList[i]), length(inputList[[i]])), value=inputList[[i]]) }) do.call('rbind', ldf) } yulab.utils/R/bib-ggtree.R0000644000176200001440000002305314656277555015111 0ustar liggesusersbib_ggtree <- function(id) { bib <- c( jgg2024 = bib_shinyTempSignal_jgg2024, bib2022 = bib_ggmsa_bib2022, book = bib_ggtree_book2022, imeta2022 = bib_ggtree_imeta2022, cpb2020 = bib_ggtree_cpb2020, mbe2020 = bib_treeio_mbe2020, mbe2018 = bib_ggtree_mbe2018, mee2017 = bib_ggtree_mee2017 ) if (!id %in% names(bib)) return(NULL) bib[id] } ref_ggtree <- function() { refs <- c( shinyTempSignal = paste( "L Zhan, X Luo, W Xie, XA Zhu, Z Xie, J Lin, L Li, W Tang, R Wang, L Deng, Y Liao, B Liu, Y Cai, Q Wang, S Xu, G Yu.", "shinyTempSignal: an R shiny application for exploring temporal and other phylogenetic signals.", "Journal of Genetics and Genomics 2024, 51(7):762-768. doi: 10.1016/j.jgg.2024.02.004"), ggtreeBook = paste( "Guangchuang Yu. ", "Data Integration, Manipulation and Visualization of Phylogenetic Trees (1st edition).", "Chapman and Hall/CRC. 2022, doi:10.1201/9781003279242, ISBN: 9781032233574\n"), ggtreeCPB = paste0( "Guangchuang Yu. ", "Using ggtree to visualize data on tree-like structures. ", "Current Protocols in Bioinformatics. 2020, 69:e96. doi:10.1002/cpbi.96\n" ), ggtree_imeta = paste0( "Shuangbin Xu, Lin Li, Xiao Luo, Meijun Chen, Wenli Tang, Li Zhan, Zehan Dai, Tommy T. Lam, Yi Guan, Guangchuang Yu. ", "Ggtree: A serialized data object for visualization of a phylogenetic tree and annotation data. ", "iMeta 2022, 1(4):e56. doi:10.1002/imt2.56\n"), ggtreeMBE = paste0( "Guangchuang Yu, Tommy Tsan-Yuk Lam, Huachen Zhu, Yi Guan. ", "Two methods for mapping and visualizing associated data on phylogeny using ggtree. ", "Molecular Biology and Evolution. 2018, 35(12):3041-3043. doi:10.1093/molbev/msy194\n" ), ggtree = paste0( "Guangchuang Yu, David Smith, Huachen Zhu, Yi Guan, Tommy Tsan-Yuk Lam. ", "ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data. ", "Methods in Ecology and Evolution. 2017, 8(1):28-36. doi:10.1111/2041-210X.12628\n" ), treeio = paste0( "LG Wang, TTY Lam, S Xu, Z Dai, L Zhou, T Feng, P Guo, CW Dunn, BR Jones, T Bradley, H Zhu, Y Guan, Y Jiang, G Yu. ", "treeio: an R package for phylogenetic tree input and output with richly annotated and associated data. ", "Molecular Biology and Evolution. 2020, 37(2):599-603. doi: 10.1093/molbev/msz240\n" ), ggtreeExtra = paste0( "S Xu, Z Dai, P Guo, X Fu, S Liu, L Zhou, W Tang, T Feng, M Chen, L Zhan, T Wu, E Hu, Y Jiang, X Bo, G Yu. ", "ggtreeExtra: Compact visualization of richly annotated phylogenetic data. ", "Molecular Biology and Evolution. 2021, 38(9):4039-4042. doi: 10.1093/molbev/msab166\n" ), ggmsa = paste( "L Zhou, T Feng, S Xu, F Gao, TT Lam, Q Wang, T Wu, H Huang, L Zhan, L Li, Y Guan, Z Dai, G Yu.", "ggmsa: a visual exploration tool for multiple sequence alignment and associated data.", "Bioinformatics. 2022, 23(4):bbac222. 10.1093/bib/bbac222" ) ) return(refs) } refs <- ref_ggtree() bib_ggtree_book2022 <- bibentry( bibtype = "book", title = "Data Integration, Manipulation and Visualization of Phylogenetic Treess", author = person("Guangchuang", "Yu"), publisher = "Chapman and Hall/{CRC}", year = "2022", edition = "1st edition", doi = "10.1201/9781003279242", url = "https://www.amazon.com/Integration-Manipulation-Visualization-Phylogenetic-Computational-ebook/dp/B0B5NLZR1Z/", textVersion = refs['ggtreeBook'] ) bib_ggtree_imeta2022 <- bibentry( bibtype = "article", title = "Ggtree: A serialized data object for visualization of a phylogenetic tree and annotation data", author = personList( person("Shuangbin", "Xu"), person("Lin", "Li"), person("Xiao", "Luo"), person("Meijun", "Chen"), person("Wenli", "Tang"), person("Li", "Zhan"), person("Zehan", "Dai"), person("Tommy T. Lam"), person("Yi", "Guan"), person("Guangchuang", "Yu") ), year = "2022", journal = "iMeta", volume = "1", number = "4", pages = "e56", doi = "10.1002/imt2.56", url = "https://onlinelibrary.wiley.com/doi/full/10.1002/imt2.56", textVersion = refs['ggtree_imeta'] ) bib_ggtree_cpb2020 <- bibentry( bibtype = "article", title = "Using ggtree to Visualize Data on Tree-Like Structures", author = person("Guangchuang", "Yu"), year = "2020", journal = "Current Protocols in Bioinformatics", volume = "69", pages = "e96", number = "1", url = "https://currentprotocols.onlinelibrary.wiley.com/doi/abs/10.1002/cpbi.96", doi = "10.1002/cpbi.96", textVersion = refs['ggtreeCPB'] ) bib_ggtree_mbe2018 <- bibentry( bibtype = "article", title = "Two methods for mapping and visualizing associated data on phylogeny using ggtree.", author = personList( as.person("Guangchuang Yu"), as.person("Tommy Tsan-Yuk Lam"), as.person("Huachen Zhu"), as.person("Yi Guan") ), year = "2018", journal = "Molecular Biology and Evolution", volume = "35", issue = "2", number = "", pages = "3041-3043", doi = "10.1093/molbev/msy194", PMID = "", url = "https://academic.oup.com/mbe/article/35/12/3041/5142656", textVersion = refs['ggtreeMBE'] ) bib_ggtree_mee2017 <- bibentry( bibtype = "article", title = "ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data.", author = personList( as.person("Guangchuang Yu"), as.person("David Smith"), as.person("Huachen Zhu"), as.person("Yi Guan"), as.person("Tommy Tsan-Yuk Lam") ), year = "2017", journal = "Methods in Ecology and Evolution", volume = "8", issue = "1", number = "", pages = "28-36", doi = "10.1111/2041-210X.12628", PMID = "", url = "http://onlinelibrary.wiley.com/doi/10.1111/2041-210X.12628/abstract", textVersion = refs['ggtree'] ) bib_shinyTempSignal_jgg2024 <-bibentry( bibtype = "article", title = "shinyTempSignal: an R shiny application for exploring temporal and other phylogenetic signals.", author = c( person("Li", "Zhan"), person("Xiao", "Luo"), person("Wenqin", "Xie"), person("Xuan-An", "Zhu"), person("Zijing", "Xie"), person("Jianfeng", "Lin"), person("Lin", "Li"), person("Wenli", "Tang"), person("Rui", "Wang"), person("Lin", "Deng"), person("Yufan", "Liao"), person("Bingdong", "Liu"), person("Yantong", "Cai"), person("Qianwen", "Wang"), person("Shuangbin", "Xu"), person("Guangchuang", "Yu") ), year = "2024", journal = "Journal of Genetics and Genomics", volume = "51", issue = "7", number = "", pages = "762-768", doi = "10.1016/j.jgg.2024.02.004", PMID = "", url = "https://www.sciencedirect.com/science/article/pii/S167385272400033X", textVersion = refs['shinyTempSignal'] ) bib_treeio_mbe2020 <- bibentry( bibtype = "article", title = "treeio: an R package for phylogenetic tree input and output with richly annotated and associated data.", author = c( person("Li-Gen", "Wang"), person("Tommy Tsan-Yuk", "Lam"), person("Shuangbin", "Xu"), person("Zehan", "Dai"), person("Lang", "Zhou"), person("Tingze", "Feng"), person("Pingfan", "Guo"), person("Casey W.", "Dunn"), person("Bradley R.", "Jones"), person("Tyler", "Bradley"), person("Huachen", "Zhu"), person("Yi", "Guan"), person("Yong", "Jiang"), person("Guangchuang", "Yu") ), year = "2020", journal = "Molecular Biology and Evolution", volume = "37", issue = "2", number = "", pages = "599-603", doi = "10.1093/molbev/msz240", PMID = "", url = "", textVersion = refs['treeio'] ) bib_ggmsa_bib2022 <- citEntry( entry = "article", title = "ggmsa: a visual exploration tool for multiple sequence alignment and associated data ", author = personList( as.person("Lang Zhou"), as.person("Tingze Feng"), as.person("Shuangbin Xu"), as.person("Fangluan Gao"), as.person("Tommy T Lam"), as.person("Qianwen Wang"), as.person("Tianzhi Wu"), as.person("Huina Huang"), as.person("Li Zhan"), as.person("Lin Li"), as.person("Yi Guan"), as.person("Zehan Dai"), as.person("Guangchuang Yu") ), journal = "BRIEFINGS IN BIOINFORMATICS", volume = "23", issue = "4", year = "2022", month = "06", ISSN = "1467-5463", doi = "10.1093/bib/bbac222", PMID = "35671504", url = "https://academic.oup.com/bib/article-abstract/23/4/bbac222/6603927", textVersion = refs['ggmsa'] ) yulab.utils/R/biorxiv.R0000644000176200001440000000264714404503310014536 0ustar liggesusers## biorxiv_get_publication <- function(url) { ## # url <- "https://www.biorxiv.org/search/visualization%20numresults%3A75%20sort%3Arelevance-rank" ## x <- readLines(url) ## pub <- x[grep("/content/10.1101", x)] ## pub_url <- gsub(".*(/content/[[:digit:]\\.v/]+).*", "\\1", pub) ## pub_url <- paste0("https://www.biorxiv.org", pub_url) ## pub_title <- gsub("<[^>]+>", "", pub) %>% ## sub("^\\s+", "", .) %>% ## sub("\\s+$", "", .) ## data.frame(url = pub_url, ## title = pub_title) ## } ## biorxiv_get_correspondance <- function(url) { ## # url <- "https://www.biorxiv.org/content/10.1101/701680v3" ## x <- readLines(url) ## i <- grep("citation_author\"", x) ## j <- grep("citation_author_email", x) ## idx <- vapply(j, function(ii) { ## jj <- ii - i ## i[which(jj == min(jj[jj >0]))] ## }, numeric(1)) ## author <- x[idx] %>% unique %>% ## sub(".*content=\"([^\"]+).*", "\\1", .) ## email <- x[j] %>% unique %>% ## sub(".*content=\"([^\"]+).*", "\\1", .) ## data.frame(author = author, email = email) %>% unique ## } ## url <- "https://www.biorxiv.org/search/visualization%20numresults%3A75%20sort%3Arelevance-rank" ## y <- biorxiv_get_publication(url) ## xx <- lapply(y$url, function(x) { ## cat("parsing", x, "\n") ## biorxiv_get_correspondance(x) ## }) yulab.utils/R/file.R0000644000176200001440000001065314660051033013773 0ustar liggesusers#' @rdname yread #' @export yread_tsv <- function(file, reader = utils::read.delim, params = list(), cache_dir = tempdir() ) { # e.g. params = list(sep = "\t", header = FALSE) yread(file, reader = reader, params = params, cache_dir = cache_dir ) } #' read file with caching #' #' This function read a file (local or url) and cache the content. #' @title yread #' @rdname yread #' @param file a file or url #' @param reader a function to read the 'file_url' #' @param params a list of parameters that passed to the 'reader' #' @param cache_dir a folder to store cache files. If set to NULL will disable cache. #' @return the output of using the 'reader' to read the 'file_url' with parameters specified by the 'params' #' @author Yonghe Xia and Guangchuang Yu #' @importFrom fs path_join #' @importFrom digest digest #' @export yread <- function(file, reader = readLines, params = list(), cache_dir = NULL) { if (!is.null(cache_dir)) { # Generate a unique cache filename based on the file URL cache_filename <- fs::path_join(c(cache_dir, paste0(digest::digest(file), ".rds"))) } else { cache_filename <- NULL } # Check if the cached file exists if (!is.null(cache_filename) && file.exists(cache_filename)) { # If cached file exists, load and return the cached data cached_data <- readRDS(cache_filename) return(cached_data) } else { # If cached file does not exist, read and cache the data data <- do.call(reader, args = c(file, params)) if (!is.null(cache_filename)) { saveRDS(data, cache_filename) } return(data) } } ##' read clipboard ##' ##' ##' @title read.cb ##' @param reader function to read the clipboard ##' @param ... parameters for the reader ##' @return clipboard content, output type depends on the output of the reader ##' @author Guangchuang Yu ##' @importFrom utils read.table ##' @export read.cb <- function(reader = read.table, ...) { os <- which_os() if (os == "Darwin") { clip <- pipe("pbpaste") } else { clip <- "clipboard" } reader(clip, ...) } ##' open selected directory or file ##' ##' ##' @title o ##' @param file to be open; open working directory by default ##' @return No return value, called for opening specific directory or file ##' @examples ##' \dontrun{ ##' ## to open current working directory ##' o() ##' } ##' @export ##' @author Guangchuang Yu o <- function(file=".") { file <- normalizePath(file) os <- which_os() if (is.rserver()) { if (dir.exists(file)) { stop("open directory in RStudio Server is not supported.") } rserver_ip <- getOption("rserver_ip") if (!is.null(rserver_ip)) { rserver_port <- getOption("rserver_port") %||% '8787' if (!startsWith(rserver_ip, "http")) { rserver_ip <- paste0("http://", rserver_ip) } utils::browseURL( paste0( paste(rserver_ip, rserver_port, sep=":"), "/file_show?path=", file )) } else { file.edit <- get("file.edit") file.edit(file) } } else if (os == "Darwin") { cmd <- paste("open", file) system(cmd) } else if (os == "Linux") { cmd <- paste("xdg-open", file, "&") system(cmd) } else if (os == "Windows") { ## wd <- sub("/", "\\", getwd()) ## cmd <- paste("explorer", wd) ## suppressWarnings(shell(cmd)) cmd <- paste("start", file) shell(cmd) } } is.rserver <- function(){ RStudio.Version <- tryCatch(get("RStudio.Version"), error = function(e) NULL) if(is.null(RStudio.Version)) return(FALSE) if(!is.function(RStudio.Version)) return(FALSE) RStudio.Version()$mode == 'server' } ##' Open data frame in Excel. It can be used in pipe. ##' ##' ##' @title show_in_excel ##' @param .data a data frame to be open ##' @return original .data ##' @export ##' @author Guangchuang Yu show_in_excel <- function(.data) { f <- tempfile(fileext = '.csv') utils::write.csv(.data, file=f) o(f) invisible(.data) } yulab.utils/R/sudo-install.R0000644000176200001440000000113214444013464015470 0ustar liggesuserssudo_install <- function(pkgs) { ## pkgs_str <- paste0('"', pkgs, '"') %>% ## paste(collapse=',') %>% ## paste("c(", ., ")") ## rcmd0 <- 'options(repos = c(CRAN = "https://mirrors.e-ducation.cn/CRAN/"));' os <- Sys.info()[1] if (os == "Windows") { sudo <- "" } else { sudo <- "sudo" } for (pkg in pkgs) { pkg <- paste0('"', pkg, '"') rcmd <- paste0('install.packages(', pkg, ')') ## rcmd <- paste0(rcmd0, rcmd) cmd <- paste0(sudo, " Rscript -e '", rcmd, "'") system(cmd) } } yulab.utils/R/install_zip.R0000644000176200001440000000413014660013201015370 0ustar liggesusers##' install github package ##' ##' it download the zip file first and use `install_zip` to install it ##' @title install_zip_gh ##' @param repo github repo ##' @param ref github branch, default is HEAD, which means the default branch of the GitHub repo ##' @param args argument to build package ##' @return No return value, called for installing github package ##' @importFrom utils download.file ##' @export ##' @author Guangchuang Yu install_zip_gh <- function(repo, ref = "HEAD", args = "--no-build-vignettes") { ## repo <- 'GuangchuangYu/nCov2019' url <- paste0('https://codeload.github.com/', repo, '/zip/', ref) f <- tempfile(fileext=".zip") mydownload(url, destfile = f) if (!is_valid_zip(f)) { stop("Invalid zip file downloaded, please check the 'ref' parameter to set a correct github branch.") } install_zip(f, args=args) } ##' install R package from zip file of source codes ##' ##' ##' @title install_zip ##' @param file zip file ##' @param args argument to build package ##' @return No return value, called for install R package from zip file of source codes ##' @export ##' @author Guangchuang Yu install_zip <- function(file, args = "--no-build-vignettes") { dir <- tempfile() utils::unzip(file, exdir=dir) fs <- list.files(path=dir, full.names=T) #if (length(fs) == 1 && dir.exists(fs)) { # dir <- fs #} ## dir <- paste0(dir, '/', basename(repo), '-master') dir <- fs[which.max(file.info(fs)$atime)] if ("INDEX" %in% list.files(dir)) { # file is binary package pkg <- file } else { # file is zip of package source ## remotes::install_local(path=dir, ..., force=TRUE) ## pkg <- pkgbuild::build(dir, args=args) build <- get_fun_from_pkg('pkgbuild', 'build') pkg <- build(dir, args=args) } utils::install.packages(pkg, repos=NULL) } is_valid_zip <- function(zipfile) { fs <- tryCatch(utils::unzip(zipfile, list=TRUE), error = function(e) NULL) if (is.null(fs)) return(FALSE) return(TRUE) } yulab.utils/R/bib-knownledge.R0000644000176200001440000002662614713050757015765 0ustar liggesusersbib_knownledge <- function(id) { bib <- c( innovation2024 = bib_clusterProfiler_innovation2024, np2024 = bib_clusterProfiler_np2024, innovation2021 = bib_clusterProfiler_innovation2021, omics2012 = bib_clusterProfiler_omics2012, chipseeker2022 = bib_chipseeker_cp2022, chipseeker2015 = bib_chipseeker_bioinfo2015, gosemsim2020 = bib_gosemsim_mmb2020, gosemsim2010 = bib_gosemsim_bioinfo2010, meshes2018 = bib_meshes_bioinfo2018, reactome2016 = bib_reactomepa_mbs20016, dose2015 = bib_dose_bioinfo2015 ) if (!id %in% names(bib)) return(NULL) bib[id] } ref_knownledge <- function() { refs <- c( ChIPseeker_CP = paste( "Qianwen Wang, Ming Li, Tianzhi Wu, Li Zhan, Lin Li, Meijun Chen, Wenqin Xie, Zijing Xie, Erqiang Hu, Shuangbin Xu, Guangchuang Yu.", "Exploring epigenomic datasets by ChIPseeker.", "Current Protocols. 2022, 2(10): e585"), ChIPseeker = paste( "Guangchuang Yu, Li-Gen Wang, and Qing-Yu He.", "ChIPseeker: an R/Bioconductor package for ChIP peak annotation, comparison and visualization.", "Bioinformatics. 2015, 31(14):2382-2383"), GOSemSim_MMB = paste( "Guangchuang Yu.", "Gene Ontology Semantic Similarity Analysis Using GOSemSim.", "In: Kidder B. (eds) Stem Cell Transcriptional Networks.", "Methods in Molecular Biology. 2020, 2117:207-215.", "Humana, New York, NY."), GOSemSim = paste( "Guangchuang Yu, Fei Li, Yide Qin, Xiaochen Bo, Yibo Wu and Shengqi Wang.", "GOSemSim: an R package for measuring semantic similarity among GO terms and gene products.", "Bioinformatics. 2010, 26(7):976-978"), DOSE = paste( "Guangchuang Yu, Li-Gen Wang, Guang-Rong Yan, Qing-Yu He.", "DOSE: an R/Bioconductor package for Disease Ontology Semantic and Enrichment analysis.", "Bioinformatics. 2015, 31(4):608-609"), ReactomePA = paste( "Guangchuang Yu, Qing-Yu He.", "ReactomePA: an R/Bioconductor package for reactome pathway analysis and visualization.", "Molecular BioSystems. 2016, 12(2):477-479"), clusterProfiler_NP = paste( "S Xu, E Hu, Y Cai, Z Xie, X Luo, L Zhan, W Tang,", "Q Wang, B Liu, R Wang, W Xie, T Wu, L Xie, G Yu.", "Using clusterProfiler to characterize multiomics data.", "Nature Protocols. 2024, 19(11):3292-3320"), clusterProfiler_Innovation2024 = paste( "G Yu.", "Thirteen years of clusterProfiler.", "The Innovation. 2024, 5(6):100722"), clusterProfiler_Innovation = paste( "T Wu, E Hu, S Xu, M Chen, P Guo, Z Dai, T Feng, L Zhou,", "W Tang, L Zhan, X Fu, S Liu, X Bo, and G Yu.", "clusterProfiler 4.0: A universal enrichment tool for interpreting omics data.", "The Innovation. 2021, 2(3):100141"), clusterProfiler = paste( "Guangchuang Yu, Li-Gen Wang, Yanyan Han and Qing-Yu He.", "clusterProfiler: an R package for comparing biological themes among gene clusters.", "OMICS: A Journal of Integrative Biology. 2012, 16(5):284-287"), meshes = paste( "Guangchuang Yu.", "Using meshes for MeSH term enrichment and semantic analyses.", "Bioinformatics. 2018, 34(21):3766-3767, doi:10.1093/bioinformatics/bty410") ) return(refs) } ref2 <- ref_knownledge() bib_clusterProfiler_innovation2024 <- citEntry( entry ="ARTICLE", title = "Thirteen years of clusterProfiler", author = c(person("Guangchuang", "Yu")), url = "https://doi.org/10.1016/j.xinn.2024.100722", doi = "10.1016/j.xinn.2024.100722", journal = "The Innovation", month = "Nov", year = "2024", volume = "5", number = "6", pages = "100722", textVersion = ref2['clusterProfiler_Innovation2024'] ) bib_clusterProfiler_np2024 <- citEntry( entry ="ARTICLE", title = "Using clusterProfiler to characterize multiomics data", author = c( person("Shuangbin", "Xu"), person("Erqiang", "Hu"), person("Yantong", "Cai"), person("Zijing", "Xie"), person("Xiao", "Luo"), person("Li", "Zhan"), person("Wenli", "Tang"), person("Qianwen", "Wang"), person("Bingdong", "Liu"), person("Rui", "Wang"), person("Wenqin", "Xie"), person("Tianzhi", "Wu"), person("Liwei", "Xie"), person("Guangchuang", "Yu") ), issn = "1750-2799", url = "https://www.nature.com/articles/s41596-024-01020-z", doi = "10.1038/s41596-024-01020-z", journal = "Nature Protocols", month = "Nov", year = "2024", volume = "19", number = "11", pages = "3292-3320", textVersion = ref2['clusterProfiler_NP'] ) bib_clusterProfiler_innovation2021 <- citEntry(entry ="ARTICLE", title = "clusterProfiler 4.0: A universal enrichment tool for interpreting omics data", author = c( person("Tianzhi", "Wu"), person("Erqiang", "Hu"), person("Shuangbin", "Xu"), person("Meijun", "Chen"), person("Pingfan", "Guo"), person("Zehan", "Dai"), person("Tingze", "Feng"), person("Lang", "Zhou"), person("Wenli", "Tang"), person("Li", "Zhan"), person("xiaochong", "Fu"), person("Shanshan", "Liu"), person("Xiaochen", "Bo"), person("Guangchuang", "Yu") ), journal = "The Innovation", year = "2021", volume = "2", number = "3", pages = "100141", PMID = "", doi = "10.1016/j.xinn.2021.100141", textVersion = ref2['clusterProfiler_Innovation'] ) bib_clusterProfiler_omics2012 <- citEntry(entry ="ARTICLE", title = "clusterProfiler: an R package for comparing biological themes among gene clusters", author = personList( as.person("Guangchuang Yu"), as.person("Li-Gen Wang"), as.person("Yanyan Han"), as.person("Qing-Yu He") ), journal = "OMICS: A Journal of Integrative Biology", year = "2012", volume = "16", number = "5", pages = "284-287", PMID = "22455463", doi = "10.1089/omi.2011.0118", textVersion = ref2['clusterProfiler'] ) bib_meshes_bioinfo2018 <- citEntry(entry ="ARTICLE", title = "Using meshes for MeSH term enrichment and semantic analyses ", author = as.person("Guangchuang Yu"), journal = "Bioinformatics", year = "2018", volume = "34", number = "21", pages = "3766-3767", PMID = "29790928", doi = "10.1093/bioinformatics/bty410", textVersion = ref2["meshes"] ) bib_reactomepa_mbs20016 <- citEntry(entry = "ARTICLE", title = "ReactomePA: an R/Bioconductor package for reactome pathway analysis and visualization", author = c( person("Guangchuang", "Yu"), person("Qing-Yu", "He") ), journal = "Molecular BioSystems", year = "2016", volume = "12", number = "12", pages = "477-479", PMID = "26661513", url = "http://pubs.rsc.org/en/Content/ArticleLanding/2015/MB/C5MB00663E", doi = "10.1039/C5MB00663E", textVersion = ref2['ReactomePA'] ) bib_dose_bioinfo2015 <- citEntry(entry = "ARTICLE", title = "DOSE: an R/Bioconductor package for Disease Ontology Semantic and Enrichment analysis", author = c( person("Guangchuang", "Yu"), person("Li-Gen", "Wang"), person("Guang-Rong", "Yan"), person("Qing-Yu", "He") ), journal = "Bioinformatics", year = "2015", volume = "31", number = "4", pages = "608-609", PMID = "", url = "http://bioinformatics.oxfordjournals.org/content/31/4/608", doi = "10.1093/bioinformatics/btu684", textVersion = ref2['DOSE'] ) bib_chipseeker_cp2022 <- citEntry(entry ="ARTICLE", title = "Exploring epigenomic datasets by ChIPseeker", author = c( person("Qianwen", "Wang"), person("Ming", "Li"), person("Tianzhi", "Wu"), person("Li", "Zhan"), person("Lin", "Li"), person("Meijun", "Chen"), person("Wenqin", "Xie"), person("Zijing", "Xie"), person("Erqiang", "Hu"), person("Shuangbin", "Xu"), person("Guangchuang", "Yu", email = "guangchuangyu@gmail.com") ), journal = "Current Protocols", year = "2022", volume = "2", number = "10", pages = "e585", PMID = "36286622", doi = "10.1002/cpz1.585", url = "https://onlinelibrary.wiley.com/share/author/GYJGUBYCTRMYJFN2JFZZ?target=10.1002/cpz1.585", textVersion = ref2['ChIPseeker_CP'] ) bib_chipseeker_bioinfo2015 <- citEntry(entry ="ARTICLE", title = "ChIPseeker: an R/Bioconductor package for ChIP peak annotation, comparison and visualization", author = personList( as.person("Guangchuang Yu"), as.person("Li-Gen Wang"), as.person("Qing-Yu He") ), journal = "Bioinformatics", year = "2015", volume = "31", number = "14", pages = "2382-2383", PMID = "25765347", doi = "10.1093/bioinformatics/btv145", textVersion = ref2['ChIPseeker'] ) bib_gosemsim_mmb2020 <- citEntry(entry ="ARTICLE", title = "Gene Ontology Semantic Similarity Analysis Using GOSemSim", author = person("Guangchuang", "Yu"), journal = "Methods in Molecular Biology", shortjournal = "Methods Mol. Biol.", year = "2020", volume = "2117", pages = "207-215", PMID = "31960380", issn = "1940-6029", doi = "10.1007/978-1-0716-0301-7_11", textVersion = ref2['GOSemSim_MMB'] ) bib_gosemsim_bioinfo2010 <- citEntry(entry ="ARTICLE", title = "GOSemSim: an R package for measuring semantic similarity among GO terms and gene products", author = personList( as.person("Guangchuang Yu"), as.person("Fei Li"), as.person("Yide Qin"), as.person("Xiaochen Bo"), as.person("Yibo Wu"), as.person("Shengqi Wang") ), journal = "Bioinformatics", year = "2010", volume = "26", number = "7", pages = "976-978", PMID = "20179076", doi = "10.1093/bioinformatics/btq064", textVersion = ref2['GOSemSim'] ) yulab.utils/R/utilities.R0000644000176200001440000000124114741745041015071 0ustar liggesusers`%||%` <- 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(caller)) { fn <- tryCatch(eval(parse(text=caller)), error=function(e) NULL) if (is.null(fn)) return("") } else { fn <- caller } return(environmentName(environment(fn))) } yulab.utils/R/zzz.R0000644000176200001440000000034114651121636013711 0ustar liggesusers## @importFrom memoise memoise .onLoad <- function(libname, pkgname) { # yread <<- memoise::memoise(yread) # yread_tsv <<- memoise::memoise(yread_tsv) # packageStartupMessage(yulab_msg(pkgname)) } yulab.utils/R/scale.R0000644000176200001440000000056614443621642014155 0ustar liggesusers##' normalized data by range ##' ##' ##' @title scale-range ##' @param data the input data. ##' @return normalized data ##' @export ##' @author Guangchuang Yu scale_range <- function(data) { normalized_data <- apply(data, 2, function(x) { (x - min(x, na.rm = TRUE)) / (max(x, na.rm = TRUE) - min(x, na.rm = TRUE)) }) as.data.frame(normalized_data) } yulab.utils/R/yulab-utils-package.R0000644000176200001440000000004514560213723016716 0ustar liggesusers#' @keywords internal "_PACKAGE" yulab.utils/R/matrix-utils.R0000644000176200001440000000171314471061074015521 0ustar liggesusers##' convert a matrix to a tidy data frame ##' (from wide to long format as described in the tidyverse concept) ##' ##' ##' @title mat2df ##' @param x the input matrix ##' @return a data.frame in long format with the 'value' column stores the original values ##' and 'row' and 'col' columns stored in row and column index as in x ##' @examples ##' x <- matrix(1:15, nrow = 3) ##' mat2df(x) ##' @export ##' @author Guangchuang Yu mat2df <- function(x) { nr <- nrow(x) nc <- ncol(x) d <- data.frame( value = as.vector(x), row = rep(1:nr, times = nc), col = rep(1:nc, each = nr) ) return(d) } ##' convert a matrix to a list ##' ##' ##' @title mat2list ##' @param x the input matrix ##' @return a list that contains matrix columns as its elements ##' @examples ##' x <- matrix(1:15, nrow = 3) ##' mat2list(x) ##' @export mat2list <- function(x){ lapply(seq_len(ncol(x)), function(i) x[,i]) } yulab.utils/R/concat.r0000644000176200001440000000456314723520003014364 0ustar liggesusers#' chunked array #' #' concate two vector/chunked_array into a chunked_array object #' @title c2 #' @param x a vector or chunked_array object #' @param y a vector or chunked_array object #' @return chunked_array object #' @author Guangchuang Yu #' @export c2 <- function(x, y) { if (length(x) == 0) return(y) if (length(y) == 0) return(x) same_mode <- (is.numeric(x) && is.numeric(y)) || (is.character(x) && is.character(y)) if (!same_mode) stop("x and y should be both numeric or character vector.") X <- as_chunked_array(x) Y <- as_chunked_array(y) res <- structure( list( vector_list = c(X$vector_list, Y$vector_list), idx = c(X$idx, Y$idx + length(X)) ), class = "chunked_array" ) return(res) } as_chunked_array <- function(x) { if (inherits(x, "chunked_array")) return(x) if (!is.numeric(x) && !is.character(x)) { stop("only numeric/character vector supported") } structure( list( vector_list = list(x), idx = 0 ), class = "chunked_array" ) } #' @method as.vector chunked_array #' @export as.vector.chunked_array <- function(x, mode = "any") { unlist(x$vector_list) } #' @method print chunked_array #' @export print.chunked_array <- function(x, ...) { n <- length(x) msg <- sprintf("chunked array with size of %d\n", n) cat(msg) } #' @method length chunked_array #' @export length.chunked_array <- function(x) { last_item(x$idx) + length(last_item(x$vector_list)) } last_item <- function(x) { if (is.list(x)) return(x[[length(x)]]) x[length(x)] } #' @method [ chunked_array #' @export `[.chunked_array` <- function(x, i, ...) { # array_idx <- vapply(i, \(ii) last_item(which(ii > x$idx)), numeric(1)) # # pos <- i - x$idx[array_idx] # # output <- ifelse(is.numeric(x), numeric(1), character(1)) # vapply(seq_along(i), \(j) x$vector_list[[array_idx[j]]][pos[j]], output) as.vector(x)[i] # faster :) } #' @method is.numeric chunked_array #' @export is.numeric.chunked_array <- function(x) { is.numeric(x$vector_list[[1]]) } #' @method is.character chunked_array #' @export is.character.chunked_array <- function(x) { is.character(x$vector_list[[1]]) } yulab.utils/R/regexpr.R0000644000176200001440000000402114660772537014543 0ustar liggesusers##' @rdname regexpr-style ##' @export set_PCRE <- function() { options(regexpr_use_perl = TRUE) } ##' @rdname regexpr-style ##' @export set_TRE <- function() { options(regexpr_use_perl = FALSE) } ##' @rdname regexpr-style ##' @export use_perl <- function() { res <- getOption("regexpr_use_perl", default = auto_set_regexpr_style()) return(res) } ##' switch regular expression style (PCRE vs TRE) ##' ##' The `set_regexpr_style()` allows user to specify which style to be used, ##' while the `auto_set_regexpr_style()` automatically set the style depdending on ##' the operating system (TRE for Windows and PCRE for other OSs (Linux and Mac)). ##' ##' `set_PCRE()` force to use PCRE style while `set_TRE()` force to use TRE. ##' ##' Note that all these functions are not change the behavior of `gsub()` and `regexpr()`. ##' The functions are just set a global option to store the user's choice of whether using `perl = TRUE`. ##' ##' Users can access the option via `use_perl()` and pass the return value to `gusb()` or `regexpr()` to specify the style in use. ##' ##' @rdname regexpr-style ##' @param style one of 'PCRE' or 'TRE' ##' @return logical value of whether use perl ##' @references ##' @export ##' @author Guangchuang Yu set_regexpr_style <- function(style) { if (missing(style)) { message("style is not specific, set automatically.") auto_set_regexpr_style() } else { style <- match.arg(style, c("PCRE", "TRE")) if (style == "PCRE") { set_PCRE() } else { set_TRE() } } res <- getOption("regexpr_use_perl") invisible(res) } ##' @rdname regexpr-style ##' @export auto_set_regexpr_style <- function() { if (which_os() == "Windows") { set_TRE() res <- FALSE } else { set_PCRE() res <- TRUE } invisible(res) } yulab.utils/R/scihub-dl.R0000644000176200001440000000130014404503310014707 0ustar liggesusers##' download publication via scihub ##' ##' using scihub to download publication using doi ##' @rdname scihub-dl ##' @name scihub_dl ##' @param doi doi ##' @param scihub scihub website ##' @param download whether download the pdf file ##' @return pdf url ##' @author Guangchuang Yu ##' @export scihub_dl <- function(doi, scihub = 'sci-hub.tw', download=TRUE) { url <- paste0('https://', scihub, '/', doi) x <- readLines(url) i <- grep('id = "pdf"', x) pdf_url <-sub(".*(//.*\\.pdf).*", "https:\\1", x[i]) if (download) { outfile <- sub(".*/", "", pdf_url) utils::download.file(pdf_url, destfile = outfile) } invisible(pdf_url) } yulab.utils/R/str-utils.R0000644000176200001440000000646014660652642015040 0ustar liggesusers##' wraping long string to multiple lines ##' ##' ##' @title str_wrap ##' @param string input string ##' @param width the maximum number of characters before wrapping to a new line ##' @return update strings with new line character inserted ##' @export ##' @author Guangchuang Yu str_wrap <- function(string, width = getOption("width")) { ## ## speed comparison ## str_wrap() > stringr::str_wrap() > paste0(base::strwrap(), collapse = "\n") ## result <- vapply(string, FUN = function(st) { words <- list() i <- 1 while(nchar(st) > width) { if (length(grep(pattern = " ", x = st, perl = use_perl())) == 0) break y <- gregexpr(pattern = ' ', text = st, perl = use_perl()) y <- y[[1]] n <- nchar(st) y <- c(y,n) idx <- which(y < width) # When the length of first word > width if (length(idx) == 0) idx <- 1 # Split the string into two pieces # The length of first piece is small than width words[[i]] <- substring(st, 1, y[idx[length(idx)]] - 1) st <- substring(st, y[idx[length(idx)]] + 1, n) i <- i + 1 } words[[i]] <- st paste0(unlist(words), collapse="\n") }, FUN.VALUE = character(1) ) names(result) <- NULL result } ##' Detect the presence or absence of a pattern at the beginning or end of a string or string vector. ##' ##' ##' @title str_starts ##' @rdname str-starts-ends ##' @param string input string ##' @param pattern pattern with which the string starts or ends ##' @param negate if TRUE, return non-matching elements ##' @return a logical vector ##' @export ##' @author Guangchuang Yu str_starts <- function(string, pattern, negate=FALSE) { pattern <- paste0('^', pattern) str_detect(string, pattern, negate) } ##' @rdname str-starts-ends ##' @export str_ends <- function(string, pattern, negate=FALSE) { pattern <- paste0(pattern, '$') str_detect(string, pattern, negate) } ##' Detect the presentce/absence of a match ##' ##' ##' @title str_detect ##' @rdname str-detect ##' @param string input string ##' @param pattern pattern to look for ##' @param negate if TRUE, inverts the resulting boolen vector ##' @return logical vector ##' @export ##' @author Guangchuang Yu str_detect <- function(string, pattern, negate = FALSE) { ## faster than stringr::str_detect res <- grepl(pattern = pattern, x = string, perl = use_perl()) if (negate) res <- !res return(res) } ##' Extract a substring using a pattern ##' ##' ##' @title str_extract ##' @rdname str-extract ##' @param string input string ##' @param pattern a regular expression to describe the pattern to extracted from the 'string' ##' @return substring ##' @export ##' @author Guangchuang Yu str_extract <- function(string, pattern) { i <- regexpr(pattern = pattern, text = string, perl = use_perl()) j <- attr(i, 'match.length') res <- substring(string, i, i+j-1) res[res == ""] <- NA return(res) } yulab.utils/R/yulab-msg.R0000644000176200001440000000554614663031420014762 0ustar liggesusers##' Messages for R package developed by YuLab ##' ##' ##' @title yulab_msg ##' @param pkgname package name ##' @param n number of citation messages ##' @return package message ##' @export ##' @author Guangchuang Yu yulab_msg <- function(pkgname = NULL, n = 1) { pkgs_knownledge <- c("GOSemSim", "DOSE", "clusterProfiler", "meshes", "ReactomePA", "MicrobiomeProfiler", "enrichplot", "ChIPseeker") pkgs_tree <- c("tidytree", "treeio", "ggtree", "ggtreeExtra", "ggtreeSpace", "shinyTempSignal") if (pkgname %in% pkgs_knownledge) { id <- 1 } else if (pkgname %in% pkgs_tree) { id <- 2 } else { id <- 3 } header_msg <- yulab_msg_header(pkgname, id) if (id == 1) { citation_msg <- random_ref(pkgname, ref_knownledge(), random_n = n) } else if (id == 2) { citation_msg <- random_ref(pkgname, ref_ggtree(), random_n = n) } else { citation_msg <- pkg_ref(pkgname) } if (is.null(citation_msg)) return(header_msg) sprintf("%s%s", header_msg, citation_msg) } ##' @importFrom utils packageDescription yulab_msg_header <- function(pkgname = NULL, id = 3) { if (is.null(pkgname)) return(NULL) pages <- c("contribution-knowledge-mining/", "contribution-tree-data/", "") urls <- sprintf("https://yulab-smu.top/%s", pages) pkgVersion <- packageDescription(pkgname, fields = "Version") sprintf("%s v%s Learn more at %s\n\n", pkgname, pkgVersion, urls[id]) } random_ref <- function(pkgname, refs, random_n) { msg <- "Please cite:\n\n" indx <- grep(pkgname, names(refs)) if (length(indx) == 0) { refs <- sample(refs, random_n) } else if (length(indx) > random_n) { refs <- sample(refs[indx], random_n) } else { refs <- c(refs[indx], sample(refs[-indx], random_n - length(indx))) } refs <- paste0(refs, collapse="\n") if (nchar(refs) <= 0) return(NULL) paste(strwrap(paste0(msg, refs)), collapse = "\n") } pkg_ref <- function(pkgname) { refs <- c( fanyi = paste("D Wang, G Chen, L Li, S Wen, Z Xie, X Luo, L Zhan, S Xu, J Li, R Wang, Q Wang, G Yu.", "Reducing language barriers, promoting information absorption, and communication using fanyi.", "Chinese Medical Journal. 2024, 137(16):1950-1956. doi: 10.1097/CM9.0000000000003242") ) ref <- refs[pkgname] if (is.null(ref) || is.na(ref)) return(NULL) msg <- "Please cite:\n\n" str_wrap(paste0(msg, refs, "\n")) } yulab.utils/NAMESPACE0000644000176200001440000000306614723464027013762 0ustar liggesusers# Generated by roxygen2: do not edit by hand S3method("[",chunked_array) S3method(as.vector,chunked_array) S3method(is.character,chunked_array) S3method(is.numeric,chunked_array) S3method(length,chunked_array) S3method(print,chunked_array) S3method(print,exec) export(Biocpkg) export(CRANpkg) export(Githubpkg) export(auto_set_regexpr_style) export(c2) export(check_pkg) export(combinations) export(exec) export(get_cache) export(get_cache_element) export(get_cache_item) export(get_dependencies) export(get_fun_from_pkg) export(has_internet) export(initial_cache) export(initial_cache_item) export(install_zip) export(install_zip_gh) export(is.installed) export(ls2df) export(mat2df) export(mat2list) export(mypkg) export(o) export(packageTitle) export(pload) export(rbindlist) export(read.cb) export(rm_cache) export(rm_cache_item) export(scale_range) export(scihub_dl) export(set_PCRE) export(set_TRE) export(set_regexpr_style) export(show_in_excel) export(str_detect) export(str_ends) export(str_extract) export(str_starts) export(str_wrap) export(update_cache_item) export(use_perl) export(yread) export(yread_tsv) export(yulab_msg) importFrom(cli,cli_h2) importFrom(digest,digest) importFrom(fs,path_join) importFrom(rlang,as_name) importFrom(rlang,check_installed) importFrom(rlang,enquo) importFrom(tools,package_dependencies) importFrom(utils,combn) importFrom(utils,download.file) importFrom(utils,getFromNamespace) importFrom(utils,modifyList) importFrom(utils,packageDescription) importFrom(utils,read.table) yulab.utils/NEWS.md0000644000176200001440000000710514745456475013653 0ustar liggesusers# yulab.utils 0.2.0 + bug fixed in `get_caller_package()` (2025-01-08, Wed) # yulab.utils 0.1.9 + `c2()` to concate two vectors into a 'chunked_array' object (2024-12-03, Tue) # yulab.utils 0.1.8 + add new citation (The Innovation 2024) (2024-11-07, Thu) + `pload()` now supports github package (2024-11-06, Wed) + bug fixed in `pkg_ref()` (2024-08-26, Mon) # yulab.utils 0.1.7 + `has_internet()` for testing internet connection (2024-08-26, Mon) + `pkg_ref()` to access textVersion of package reference (2024-08-21, Wed) + export `str_detect()` (20024-08-19, Mon) + `user_dir()` to setup user data dir (20024-08-17, Sat) + `which_os()` to return the system name + `has_bin()` to check whether a command is exist in the system # yulab.utils 0.1.6 + `mydownload()` for downloading online file (2024-08-17, Sat) - internally use 'httr2' and is 'https' friendly + update `bib_ggtree()` and `bib_knowledge()` with all previous related publications (2024-08-12, Mon) + remove memory caching and disable file cache by default in `yread()` and `yread_tsv()` (2024-07-27, Sat) + `bib_ggtree()` and `bib_knowledge()` (2024-07-27, Sat) # yulab.utils 0.1.5 + `yulab_msg()` for startup message of packages developed by YuLab (2024-07-26, Fri) # yulab.utils 0.1.4 + `str_extract()` to extract substring using a regular expression pattern (2024--01-25, Thu) # yulab.utils 0.1.3 + with cache ability (2023-12-27, Wed) - `initial_cache()` - `initial_cache_item()` - `get_cache()` - `get_cache_item()` - `get_cache_element()` - `rm_cache_item()` - `rm_cache()` # yulab.utils 0.1.2 + mv translate functions to the 'fanyi' package (2023-12-14, Thu) + tools to switch from PCRE or TRE in regular expression (2023-12-13, Wed) # yulab.utils 0.1.1 + use `normalizePath()` in `o()` to convert file paths to canonical form (2023-10-06, Fri, #4) + change the default parameter, `ref = "master"` to `ref = "HEAD"` in the `install_zip_gh()` function to use the default branch of the GitHub repo (2023-10-02, Mon) # yulab.utils 0.1.0 + `install_zip()` allows both binary and source zip files (2023-09-20, Wed) + `pload()` for loading package with the ability to install it if not available (2023-09-16, Sat) + `get_dependencies()` and `packageTitle()` (2023-09-11, Mon) + import 'fs' and 'digest' (2023-09-07, Thu) # yulab.utils 0.0.9 + `ls2df()` convert list of vector to a data.frame (2023-09-01, Fri) # yulab.utils 0.0.8 + `mat2list()` and `combinations()` (2023-08-22, Tue) + remove default 'params' setting in `yread_tsv()` (2023-08-15, Tue) # yulab.utils 0.0.7 + update `check_pkg()` to call `rlang::check_installed()` with reason set automatically (2023-08-03, Thu) + `yread()` and `yread_tsv()` that read file with caching (2023-08-02, Wed) + `rbindlist()` to rbind a list (2023-08-01, Tue) + `exec()` to run system command (2023-06-19, Mon) + `scale_range()` to normalize data by range (2023-06-18, Sun) # yulab.utils 0.0.6 + `mat2df()` to convert matrix to a tidy data frame (2022-12-20, Tue) + `str_starts()` and `str_ends()` (2022-07-29, Fri) # yulab.utils 0.0.5 + `get_fun_from_pkg()` outputs friendly message if the pkg is not installed (2022-06-08, Wed) + `show_in_excel()`, `CRANpkg()`, `Biocpkg()`, `Githubpkg()`, `mypkg()` (2021-10-13, Wed) # yulab.utils 0.0.4 + `str_wrap()` (2021-10-09, Sat) # yulab.utils 0.0.3 + `read.cb()` (2021-08-17) # yulab.utils 0.0.2 + `o()`, `install_zip()`, `get_fun_from_pkg()` # yulab.utils 0.0.1 + `is.installed()`, `scihub_dl()`, `sudo_install()` yulab.utils/inst/0000755000176200001440000000000014660651434013513 5ustar liggesusersyulab.utils/inst/prototype/0000755000176200001440000000000014723463462015562 5ustar liggesusersyulab.utils/inst/prototype/sra.r0000644000176200001440000000036414712366206016531 0ustar liggesusersget_runinfo <- function(sra_id) { x <- rentrez::entrez_fetch(db='sra', rettype='runinfo', id = sra_id) read.csv(textConnection(x)) } id <- "SRX5137765" d <- get_runinfo(id) head(d,2) sprintf("fastq-dump %s", d$Run[1:3]) yulab.utils/inst/prototype/GEO.r0000644000176200001440000000142014712361503016343 0ustar liggesusers get_gse <- function(gseID) { gsecat <- sub("\\d{3}$", "nnn", gseID) gsesoft <- sprintf("%s_family.soft.gz", gseID) url <- sprintf("https://ftp.ncbi.nlm.nih.gov/geo/series/%s/%s/soft/%s", gsecat, gseID, gsesoft) yulab.utils:::mydownload(url, destfile = gsesoft) GEOquery::getGEO(filename = gsesoft) } get_gsm <- function(gse, item = "supplementary_file_1") { lapply(GEOquery::GSMList(gse), function(x) x@header[item]) } download_gsm <- function(gsm) { for (x in gsm) { destfile <- sub(".*/([^/]+)$", "\\1", x) yulab.utils:::mydownload(x, destfile = destfile) } } gseID <- "GSE123904" gse <- get_gse(gseID) gsm <- get_gsm(gse) get_gsm(gse, 'extract_protocol_ch1') |> head(2) download_gsm(gsm) yulab.utils/man/0000755000176200001440000000000014723464027013311 5ustar liggesusersyulab.utils/man/regexpr-style.Rd0000644000176200001440000000244314536214433016411 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/regexpr.R \name{set_PCRE} \alias{set_PCRE} \alias{set_TRE} \alias{use_perl} \alias{set_regexpr_style} \alias{auto_set_regexpr_style} \title{switch regular expression style (PCRE vs TRE)} \usage{ set_PCRE() set_TRE() use_perl() set_regexpr_style(style) auto_set_regexpr_style() } \arguments{ \item{style}{one of 'PCRE' or 'TRE'} } \value{ logical value of whether use perl } \description{ The \code{set_regexpr_style()} allows user to specify which style to be used, while the \code{auto_set_regexpr_style()} automatically set the style depdending on the operating system (TRE for Windows and PCRE for other OSs (Linux and Mac)). } \details{ \code{set_PCRE()} force to use PCRE style while \code{set_TRE()} force to use TRE. Note that all these functions are not change the behavior of \code{gsub()} and \code{regexpr()}. The functions are just set a global option to store the user's choice of whether using \code{perl = TRUE}. Users can access the option via \code{use_perl()} and pass the return value to \code{gusb()} or \code{regexpr()} to specify the style in use. } \references{ \url{https://stackoverflow.com/questions/47240375/regular-expressions-in-base-r-perl-true-vs-the-default-pcre-vs-tre} } \author{ Guangchuang Yu } yulab.utils/man/install_zip_gh.Rd0000644000176200001440000000121214506453666016610 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/install_zip.R \name{install_zip_gh} \alias{install_zip_gh} \title{install_zip_gh} \usage{ install_zip_gh(repo, ref = "HEAD", args = "--no-build-vignettes") } \arguments{ \item{repo}{github repo} \item{ref}{github branch, default is HEAD, which means the default branch of the GitHub repo} \item{args}{argument to build package} } \value{ No return value, called for installing github package } \description{ install github package } \details{ it download the zip file first and use \code{install_zip} to install it } \author{ Guangchuang Yu } yulab.utils/man/yulab_msg.Rd0000644000176200001440000000057214650622152015560 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/yulab-msg.R \name{yulab_msg} \alias{yulab_msg} \title{yulab_msg} \usage{ yulab_msg(pkgname = NULL, n = 1) } \arguments{ \item{pkgname}{package name} \item{n}{number of citation messages} } \value{ package message } \description{ Messages for R package developed by YuLab } \author{ Guangchuang Yu } yulab.utils/man/str_wrap.Rd0000644000176200001440000000073314660652103015436 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/str-utils.R \name{str_wrap} \alias{str_wrap} \title{str_wrap} \usage{ str_wrap(string, width = getOption("width")) } \arguments{ \item{string}{input string} \item{width}{the maximum number of characters before wrapping to a new line} } \value{ update strings with new line character inserted } \description{ wraping long string to multiple lines } \author{ Guangchuang Yu } yulab.utils/man/yulab-cache.Rd0000644000176200001440000000254014543172523015753 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/cache.R \name{initial_cache} \alias{initial_cache} \alias{get_cache} \alias{rm_cache} \alias{initial_cache_item} \alias{get_cache_item} \alias{rm_cache_item} \alias{update_cache_item} \alias{get_cache_element} \title{cache intermediate data} \usage{ initial_cache() get_cache() rm_cache() initial_cache_item(item) get_cache_item(item) rm_cache_item(item) update_cache_item(item, elements) get_cache_element(item, elements) } \arguments{ \item{item}{the name of the cached item} \item{elements}{elements to be cached in the item} } \value{ return the cache environment, item or selected elements, depends on the functions. } \description{ Yulab provides a set of utilities to cache intermediate data, including initialize the cached item, update cached item and rmove the cached item, etc. } \examples{ \dontrun{ slow_fib <- function(x) { if (x < 2) return(1) slow_fib(x-2) + slow_fib(x-1) } fast_fib <- function(x) { if (x < 2) return(1) res <- get_cache_element('fibonacci', as.character(x)) if (!is.null(res)) { return(res) } res <- fast_fib(x-2) + fast_fib(x-1) e <- list() e[[as.character(x)]] <- res update_cache_item('fibonacci', e) return(res) } system.time(slow_fib(30)) system.time(fast_fib(30)) } } yulab.utils/man/str-detect.Rd0000644000176200001440000000067714660652103015662 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/str-utils.R \name{str_detect} \alias{str_detect} \title{str_detect} \usage{ str_detect(string, pattern, negate = FALSE) } \arguments{ \item{string}{input string} \item{pattern}{pattern to look for} \item{negate}{if TRUE, inverts the resulting boolen vector} } \value{ logical vector } \description{ Detect the presentce/absence of a match } \author{ Guangchuang Yu } yulab.utils/man/scihub-dl.Rd0000644000176200001440000000072614404503310015440 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/scihub-dl.R \name{scihub_dl} \alias{scihub_dl} \title{download publication via scihub} \usage{ scihub_dl(doi, scihub = "sci-hub.tw", download = TRUE) } \arguments{ \item{doi}{doi} \item{scihub}{scihub website} \item{download}{whether download the pdf file} } \value{ pdf url } \description{ using scihub to download publication using doi } \author{ Guangchuang Yu } yulab.utils/man/read.cb.Rd0000644000176200001440000000065714462474155015111 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/file.R \name{read.cb} \alias{read.cb} \title{read.cb} \usage{ read.cb(reader = read.table, ...) } \arguments{ \item{reader}{function to read the clipboard} \item{...}{parameters for the reader} } \value{ clipboard content, output type depends on the output of the reader } \description{ read clipboard } \author{ Guangchuang Yu } yulab.utils/man/install_zip.Rd0000644000176200001440000000074414404503310016116 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/install_zip.R \name{install_zip} \alias{install_zip} \title{install_zip} \usage{ install_zip(file, args = "--no-build-vignettes") } \arguments{ \item{file}{zip file} \item{args}{argument to build package} } \value{ No return value, called for install R package from zip file of source codes } \description{ install R package from zip file of source codes } \author{ Guangchuang Yu } yulab.utils/man/o.Rd0000644000176200001440000000070214510021774014025 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/file.R \name{o} \alias{o} \title{o} \usage{ o(file = ".") } \arguments{ \item{file}{to be open; open working directory by default} } \value{ No return value, called for opening specific directory or file } \description{ open selected directory or file } \examples{ \dontrun{ ## to open current working directory o() } } \author{ Guangchuang Yu } yulab.utils/man/combinations.Rd0000644000176200001440000000046514471060707016267 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/combinations.R \name{combinations} \alias{combinations} \title{combinations} \usage{ combinations(n) } \arguments{ \item{n}{number of sets} } \value{ a list of all combinations } \description{ all possible combinations of n sets } yulab.utils/man/yread.Rd0000644000176200001440000000147114651201530014673 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/file.R \name{yread_tsv} \alias{yread_tsv} \alias{yread} \title{yread} \usage{ yread_tsv( file, reader = utils::read.delim, params = list(), cache_dir = tempdir() ) yread(file, reader = readLines, params = list(), cache_dir = NULL) } \arguments{ \item{file}{a file or url} \item{reader}{a function to read the 'file_url'} \item{params}{a list of parameters that passed to the 'reader'} \item{cache_dir}{a folder to store cache files. If set to NULL will disable cache.} } \value{ the output of using the 'reader' to read the 'file_url' with parameters specified by the 'params' } \description{ read file with caching } \details{ This function read a file (local or url) and cache the content. } \author{ Yonghe Xia and Guangchuang Yu } yulab.utils/man/mat2df.Rd0000644000176200001440000000110014474263201014737 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/matrix-utils.R \name{mat2df} \alias{mat2df} \title{mat2df} \usage{ mat2df(x) } \arguments{ \item{x}{the input matrix} } \value{ a data.frame in long format with the 'value' column stores the original values and 'row' and 'col' columns stored in row and column index as in x } \description{ convert a matrix to a tidy data frame (from wide to long format as described in the tidyverse concept) } \examples{ x <- matrix(1:15, nrow = 3) mat2df(x) } \author{ Guangchuang Yu } yulab.utils/man/packageTitle.Rd0000644000176200001440000000055414477505127016204 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/pkg-utils.R \name{packageTitle} \alias{packageTitle} \title{packageTitle} \usage{ packageTitle(pkg, repo = "CRAN") } \arguments{ \item{pkg}{package name} \item{repo}{'CRAN' and/or 'BioC'} } \value{ reverse dependencies } \description{ Extract package title } \author{ Guangchuang Yu } yulab.utils/man/has_internet.Rd0000644000176200001440000000057014663004013016251 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/os.R \name{has_internet} \alias{has_internet} \title{has_internet} \usage{ has_internet(site = "https://www.baidu.com/") } \arguments{ \item{site}{URL to test connection} } \value{ logical value } \description{ test for internect connection via reading lines from a URL } \author{ Guangchuang Yu } yulab.utils/man/c2.Rd0000644000176200001440000000061714723464027014110 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/concat.r \name{c2} \alias{c2} \title{c2} \usage{ c2(x, y) } \arguments{ \item{x}{a vector or chunked_array object} \item{y}{a vector or chunked_array object} } \value{ chunked_array object } \description{ chunked array } \details{ concate two vector/chunked_array into a chunked_array object } \author{ Guangchuang Yu } yulab.utils/man/pload.Rd0000644000176200001440000000115114501256665014676 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/pkg-utils.R \name{pload} \alias{pload} \title{pload} \usage{ pload(package, action = "auto") } \arguments{ \item{package}{package name} \item{action}{function used to install package. If 'action = "auto"', it will try to use 'BiocManager::install()' if it is available.} } \value{ the selected package loaded to the R session } \description{ loading a package } \details{ The function use 'library()' to load the package. If the package is not installed, the function will try to install it before loading it. } \author{ Guangchuang Yu } yulab.utils/man/cran-bioc-pkg.Rd0000644000176200001440000000070314404503310016175 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/pkg-utils.R \name{CRANpkg} \alias{CRANpkg} \alias{Biocpkg} \title{print md text of package with link to homepage (CRAN or Bioconductor)} \usage{ CRANpkg(pkg) Biocpkg(pkg) } \arguments{ \item{pkg}{package name} } \value{ md text string } \description{ print md text of package with link to homepage (CRAN or Bioconductor) } \author{ Guangchuang Yu } yulab.utils/man/check_pkg.Rd0000644000176200001440000000127214462656667015535 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/pkg-utils.R \name{check_pkg} \alias{check_pkg} \title{check_pkg} \usage{ check_pkg(pkg, reason = NULL, ...) } \arguments{ \item{pkg}{package names} \item{reason}{the reason to check the pkg. If NULL, it will set the reason to the parent call.} \item{...}{additional parameters that passed to \code{rlang::check_installed()}} } \value{ see also \link[rlang:is_installed]{check_installed} } \description{ Check whether the input packages are installed } \details{ This function check whether the input packages are installed. If not, it asks the user whether to install the missing packages. } \author{ Guangchuang Yu } yulab.utils/man/show_in_excel.Rd0000644000176200001440000000056214404503310016412 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/file.R \name{show_in_excel} \alias{show_in_excel} \title{show_in_excel} \usage{ show_in_excel(.data) } \arguments{ \item{.data}{a data frame to be open} } \value{ original .data } \description{ Open data frame in Excel. It can be used in pipe. } \author{ Guangchuang Yu } yulab.utils/man/exec.Rd0000644000176200001440000000050714660063734014526 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/os.R \name{exec} \alias{exec} \title{exec} \usage{ exec(command) } \arguments{ \item{command}{system command to run} } \value{ An \code{exec} instance that stores system command outputs } \description{ run system command } \author{ Guangchuang Yu } yulab.utils/man/rbindlist.Rd0000644000176200001440000000051114474316464015573 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/list.R \name{rbindlist} \alias{rbindlist} \title{rbindlist} \usage{ rbindlist(x) } \arguments{ \item{x}{a list that have similar elements that can be rbind to a data.frame} } \value{ data.frame } \description{ rbind a list } \author{ Guangchuang Yu } yulab.utils/man/get_dependencies.Rd0000644000176200001440000000061214477505127017067 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/pkg-utils.R \name{get_dependencies} \alias{get_dependencies} \title{get_dependencies} \usage{ get_dependencies(pkg, repo = c("CRAN", "BioC")) } \arguments{ \item{pkg}{package name} \item{repo}{'CRAN' and/or 'BioC'} } \value{ reverse dependencies } \description{ get reverse dependencies } \author{ Guangchuang Yu } yulab.utils/man/get_fun_from_pkg.Rd0000644000176200001440000000064014404503310017074 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/pkg-utils.R \name{get_fun_from_pkg} \alias{get_fun_from_pkg} \title{get_fun_from_pkg} \usage{ get_fun_from_pkg(pkg, fun) } \arguments{ \item{pkg}{package} \item{fun}{function} } \value{ function } \description{ load function from package } \examples{ get_fun_from_pkg('utils', 'zip') } \author{ Guangchuang Yu } yulab.utils/man/str-starts-ends.Rd0000644000176200001440000000114414474263201016647 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/str-utils.R \name{str_starts} \alias{str_starts} \alias{str_ends} \title{str_starts} \usage{ str_starts(string, pattern, negate = FALSE) str_ends(string, pattern, negate = FALSE) } \arguments{ \item{string}{input string} \item{pattern}{pattern with which the string starts or ends} \item{negate}{if TRUE, return non-matching elements} } \value{ a logical vector } \description{ Detect the presence or absence of a pattern at the beginning or end of a string or string vector. } \author{ Guangchuang Yu } yulab.utils/man/yulab.utils-package.Rd0000644000176200001440000000121214660773203017437 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/yulab-utils-package.R \docType{package} \name{yulab.utils-package} \alias{yulab.utils} \alias{yulab.utils-package} \title{yulab.utils: Supporting Functions for Packages Maintained by 'YuLab-SMU'} \description{ Miscellaneous functions commonly used by 'YuLab-SMU'. } \seealso{ Useful links: \itemize{ \item \url{https://yulab-smu.top/} \item Report bugs at \url{https://github.com/YuLab-SMU/yulab.utils/issues} } } \author{ \strong{Maintainer}: Guangchuang Yu \email{guangchuangyu@gmail.com} (\href{https://orcid.org/0000-0002-6485-8781}{ORCID}) } \keyword{internal} yulab.utils/man/mypkg.Rd0000644000176200001440000000053114404503310014707 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/pkg-utils.R \name{mypkg} \alias{mypkg} \title{mypkg} \usage{ mypkg(pkg, url) } \arguments{ \item{pkg}{package name} \item{url}{package url} } \value{ md text string } \description{ print md text of link to a pakcage } \author{ Guangchuang Yu } yulab.utils/man/scale_range.Rd0000644000176200001440000000046514443622064016044 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/scale.R \name{scale_range} \alias{scale_range} \title{scale-range} \usage{ scale_range(data) } \arguments{ \item{data}{the input data.} } \value{ normalized data } \description{ normalized data by range } \author{ Guangchuang Yu } yulab.utils/man/str-extract.Rd0000644000176200001440000000064514554357677016103 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/str-utils.R \name{str_extract} \alias{str_extract} \title{str_extract} \usage{ str_extract(string, pattern) } \arguments{ \item{string}{input string} \item{pattern}{a regular expression to describe the pattern to extracted from the 'string'} } \value{ substring } \description{ Extract a substring using a pattern } \author{ Guangchuang Yu } yulab.utils/man/ls2df.Rd0000644000176200001440000000054414474316464014621 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/list.R \name{ls2df} \alias{ls2df} \title{Convert a list of vector (e.g, gene IDs) to a data.frame object} \usage{ ls2df(inputList) } \arguments{ \item{inputList}{A list of vector} } \value{ a data.frame object. } \description{ Convert a list of vector to a data.frame object. } yulab.utils/man/mat2list.Rd0000644000176200001440000000055414474263201015335 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/matrix-utils.R \name{mat2list} \alias{mat2list} \title{mat2list} \usage{ mat2list(x) } \arguments{ \item{x}{the input matrix} } \value{ a list that contains matrix columns as its elements } \description{ convert a matrix to a list } \examples{ x <- matrix(1:15, nrow = 3) mat2list(x) } yulab.utils/man/github-pkg.Rd0000644000176200001440000000061414535556535015651 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/pkg-utils.R \name{Githubpkg} \alias{Githubpkg} \title{print md text of package with link to github repo} \usage{ Githubpkg(user, pkg) } \arguments{ \item{user}{github user} \item{pkg}{package name} } \value{ md text string } \description{ print md text of package with link to github repo } \author{ Guangchuang Yu } yulab.utils/man/is.installed.Rd0000644000176200001440000000075414404503310016160 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/pkg-utils.R \name{is.installed} \alias{is.installed} \title{is.installed} \usage{ is.installed(packages) } \arguments{ \item{packages}{package names} } \value{ logical vector } \description{ Check whether the input packages are installed } \details{ This function check whether the input packages are installed } \examples{ is.installed(c("dplyr", "ggplot2")) } \author{ Guangchuang Yu } yulab.utils/DESCRIPTION0000644000176200001440000000151214746344222014242 0ustar liggesusersPackage: yulab.utils Title: Supporting Functions for Packages Maintained by 'YuLab-SMU' Version: 0.2.0 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'. Depends: R (>= 4.2.0) Imports: cli, digest, fs, rlang, tools, utils Suggests: httr2, jsonlite, openssl, rappdirs ByteCompile: true License: Artistic-2.0 URL: https://yulab-smu.top/ BugReports: https://github.com/YuLab-SMU/yulab.utils/issues Encoding: UTF-8 RoxygenNote: 7.3.2 NeedsCompilation: no Packaged: 2025-01-29 05:58:33 UTC; HUAWEI Author: Guangchuang Yu [aut, cre] () Maintainer: Guangchuang Yu Repository: CRAN Date/Publication: 2025-01-29 06:20:02 UTC