From 602dbf221eb46bb48045d099e3d481828c484aec Mon Sep 17 00:00:00 2001 From: dipterix Date: Sun, 29 May 2022 22:49:02 -0400 Subject: [PATCH] ported multiple dipsaus package (plan to remove this dep in the next 3 versions); bump the version for CRAN --- DESCRIPTION | 17 +++++++------- NEWS.md | 1 + R/aaa.R | 40 +++++++++++++++++++++++++++++++++ R/class_proxy.R | 2 +- R/loaders.R | 49 ++++++++++++++++++++++++++++------------- R/shiny-localization.R | 2 +- R/threejs_brain.R | 10 ++++----- R/utils.R | 10 ++++----- cran-comments.md | 14 ++++++++++-- man/template_subject.Rd | 6 ++--- 10 files changed, 111 insertions(+), 40 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ea64764e..7d72f857 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: threeBrain Type: Package Title: 3D Brain Visualization -Version: 0.2.4.9003 +Version: 0.2.5 Authors@R: c( person("Zhengjia", "Wang", email = "dipterix.wang@gmail.com", role = c("aut", "cre", "cph")), person("John", "Magnotti", email = "John.Magnotti@Pennmedicine.upenn.edu", role = c("aut")), @@ -15,19 +15,20 @@ Description: A fast, interactive cross-platform, and easy to share 'WebGL'-based 3D brain viewer that visualizes 'FreeSurfer' and/or 'AFNI/SUMA' surfaces. The viewer widget can be either standalone or embedded into 'R-shiny' applications. The standalone version only require - a web browser with 'WebGL2' support (for example, 'Chrome'). It can be - inserted into any websites; see ). - as an example. The 'R-shiny' support allows the 3D viewer to be dynamically - generated from reactive user inputs. This feature has been fully adopted by - 'RAVE' , an interactive toolbox to - analyze 'iEEG/eCoG' data. Documentation about 'threeBrain' is provided + a web browser with 'WebGL2' support (for example, 'Chrome', 'Firefox', + 'Safari'). It can be inserted into any websites; see + ) as an example. The 'R-shiny' + support allows the 3D viewer to be dynamically generated from reactive user + inputs. This feature has been fully adopted by 'RAVE' + , an interactive toolbox to + analyze 'iEEG' data. Documentation about 'threeBrain' is provided by and several vignettes included in this package. To cite the package, please check our 'NeuroImage' paper by Magnotti, Wang, and Beauchamp (2020, ), or see 'citation("threeBrain")' for details. License: GPL-3 | file LICENSE Encoding: UTF-8 -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.0 Roxygen: list(r6 = FALSE) Language: en-US URL: https://dipterix.org/threeBrain/ https://github.com/dipterix/threeBrain diff --git a/NEWS.md b/NEWS.md index b6614dcc..158e94ff 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,7 @@ threeBrain 0.2.5 * Volume `fragmentShader` uses non-linear function to calculate fragment colors combined with face normal; this will create smoother results * `DataCube2` geometry uses `ConvexHull` instead of box/sphere to improve the performance * `DataCube2` are no longer hidden when `sync from voxels` is on: users can use shortcuts `l` and `k` to easily control the visibility. +* `download_template_subject` can download other templates such as `fsaverage`, `cvs_avg35`, `bert`. ## Bug fixes diff --git a/R/aaa.R b/R/aaa.R index bc545967..8059c47a 100644 --- a/R/aaa.R +++ b/R/aaa.R @@ -121,3 +121,43 @@ get_os <- function(){ } return('unknown') } + +package_installed <- function(pkgs, all = FALSE){ + re <- sapply(pkgs, function(p){ + system.file('', package = p) != '' + }) + if(all){ + re <- all(re) + } + re +} + +col2hexStr <- function(col, alpha = NULL, prefix = '#', ...){ + if(is.null(alpha)){ + alpha <- 1 + transparent <- FALSE + }else{ + transparent <- TRUE + } + re <- grDevices::adjustcolor(col, alpha.f = alpha) + if(!transparent){ + re <- substr(re, start = 1L, stop = 7L) + } + gsub('^[^0-9A-F]*', replacement = prefix, x = re) +} + +rs_avail <- function(){ + tryCatch({ + spath <- search() + if('tools:rstudio' %in% spath) { + rs_ver <- get("RStudio.Version", inherits = TRUE, envir = parent.env(globalenv())) + if(is.function(rs_ver)) { + rs_ver() + return(TRUE) + } + } + return(FALSE) + }, error = function(e){ + return(FALSE) + }) +} diff --git a/R/class_proxy.R b/R/class_proxy.R index d8dda343..5f663c56 100644 --- a/R/class_proxy.R +++ b/R/class_proxy.R @@ -68,7 +68,7 @@ ViewerProxy <- R6::R6Class( }, set_background = function(col){ - private$set_value('background', dipsaus::col2hexStr(col)) + private$set_value('background', col2hexStr(col)) }, set_zoom_level = function( zoom ){ diff --git a/R/loaders.R b/R/loaders.R index 60a9721c..e6b350e9 100644 --- a/R/loaders.R +++ b/R/loaders.R @@ -18,15 +18,27 @@ NULL #' @rdname template_subject -#' @param subject_code character with only letters and numbers (Important). Default is `N27` -#' @param url zip file address +#' @param subject_code character with only letters and numbers (Important); default is `N27` +#' @param url zip file address; must be specified if \code{subject_code} is not from the followings: \code{'bert'}, \code{'cvs_avg35'}, \code{'cvs_avg35_inMNI152'}, \code{'fsaverage'}, \code{'fsaverage_sym'}, or \code{'N27'} #' @param template_dir parent directory where subject's `FreeSurfer` folder should be stored #' @export download_template_subject <- function( - subject_code = 'N27', - url = 'https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/N27.zip', + subject_code = 'N27', url, template_dir = default_template_directory() ){ + + force(subject_code) + if(missing(url) || is.null(url)) { + avails <- available_templates() + if(!subject_code %in% names(avails)) { + stop("`download_template_subject`: please specify the url for your template if subject code is not from the followings: ", paste(names(avails), collapse = ", ")) + } + url <- avails[[subject_code]] + } + + # = 'https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/N27.zip' + + dir_create(template_dir) dir <- normalizePath(template_dir) @@ -131,15 +143,22 @@ threebrain_finalize_installation <- function(upgrade = c('ask', 'always', 'never }) if(has_n27 && upgrade %in% c('never')){ - dipsaus::cat2('N27 brain has been installed', level = 'DEFAULT') + cat2('N27 brain has been installed', level = 'DEFAULT') return(invisible()) } if(has_n27 && upgrade %in% c('ask')){ if(interactive()){ reinst <- tryCatch({ - dipsaus::ask_yesno('N27 template brain detected at \n ', template_dir, - '\nDo you want to reinstall?', error_if_canceled = FALSE) + if(package_installed("dipsaus")) { + dipsaus::ask_yesno('N27 template brain detected at \n ', template_dir, + '\nDo you want to reinstall?', error_if_canceled = FALSE) + } else { + utils::askYesNo(msg = paste0( + 'N27 template brain detected at `', template_dir, + '`. Do you want to reinstall? ' + ), default = FALSE) + } }, error = function(e){ FALSE }) @@ -148,31 +167,31 @@ threebrain_finalize_installation <- function(upgrade = c('ask', 'always', 'never } if(!isTRUE(reinst)){ - dipsaus::cat2('N27 template brain... skip', level = 'DEFAULT') + cat2('N27 template brain... skip', level = 'DEFAULT') return(invisible()) } } # install N27 brain - if( async ){ + if( async && package_installed("dipsaus") ){ code <- sprintf( "{ - dipsaus::cat2('Installing N27 template brain...', level = 'INFO') + threeBrain:::cat2('Installing N27 template brain...', level = 'INFO') threeBrain::download_N27(template_dir = '%s') # load N27 - dipsaus::cat2('Expand the template, creating cache...', level = 'INFO') + threeBrain:::cat2('Expand the template, creating cache...', level = 'INFO') threeBrain::merge_brain(template_subject = 'N27') }", template_dir) dipsaus::rs_exec(parse(text = code)[[1]], name = 'Finalize threeBrain N27 installation', quoted = TRUE) } else { - dipsaus::cat2('Installing N27 template brain...', level = 'INFO') - threeBrain::download_N27(template_dir = template_dir) + cat2('Installing N27 template brain...', level = 'INFO') + download_N27(template_dir = template_dir) # load N27 - dipsaus::cat2('Expand the template, creating cache...', level = 'INFO') - threeBrain::merge_brain(template_subject = 'N27', template_dir = template_dir) + cat2('Expand the template, creating cache...', level = 'INFO') + merge_brain(template_subject = 'N27', template_dir = template_dir) } diff --git a/R/shiny-localization.R b/R/shiny-localization.R index ff28cf2b..d8f2311e 100644 --- a/R/shiny-localization.R +++ b/R/shiny-localization.R @@ -38,7 +38,7 @@ localization_module <- function( ..., control_presets = NULL, side_display = FALSE, controllers = list() ){ - if(!dipsaus::package_installed("DT")){ + if(!package_installed("DT")){ stop("Package `DT` is needed to run this module. Please install it by running\n ", "install.packages('DT')") } diff --git a/R/threejs_brain.R b/R/threejs_brain.R index d9799579..d0c66a32 100644 --- a/R/threejs_brain.R +++ b/R/threejs_brain.R @@ -265,8 +265,8 @@ threejs_brain <- function( } # backgrounds - background <- dipsaus::col2hexStr(background) - # side_background = dipsaus::col2hexStr(side_background) + background <- col2hexStr(background) + # side_background = col2hexStr(side_background) @@ -519,7 +519,7 @@ save_brain <- function(widget, directory, filename = 'index.html', assetpath = ' } grey_col <- function(...){ - if( dipsaus::rs_avail() ){ + if( rs_avail() ){ cat("\033[38;5;246m", paste(..., sep = " ", collapse = "\n"), "\033[39m", sep = "") } else { @@ -528,7 +528,7 @@ grey_col <- function(...){ } green_col <- function(...){ - if( dipsaus::rs_avail() ){ + if( rs_avail() ){ cat("\033[38;5;35m", paste(..., sep = " ", collapse = "\n"), "\033[39m", sep = "") } else { @@ -537,7 +537,7 @@ green_col <- function(...){ } red_col <- function(...){ - if( dipsaus::rs_avail() ){ + if( rs_avail() ){ cat("\033[38;5;215m", paste(..., sep = " ", collapse = "\n"), "\033[39m", sep = "") } else { diff --git a/R/utils.R b/R/utils.R index fbbaabd9..dbd8b3d0 100644 --- a/R/utils.R +++ b/R/utils.R @@ -54,7 +54,7 @@ cat2 <- function( 'WARNING' = '#ec942c', 'ERROR' = '#f02c2c', 'FATAL' = '#763053', - 'DEFAULT' = '#000000' + 'DEFAULT' = 'grey60' ) ){ level <- toupper(level) @@ -63,11 +63,11 @@ cat2 <- function( } .col <- pal[[level]] if(is.null(.col)){ - .col <- '#000000' + .col <- 'grey60' } # check if interactive - if(dipsaus::rs_avail() && !nzchar(file)){ + if(rs_avail() && !nzchar(file)){ if(print_level){ base::cat('[', level, ']: ', sep = '') } @@ -79,10 +79,10 @@ cat2 <- function( 'WARNING' = '\033[38;5;215m', 'ERROR' = '\033[38;5;203m', 'FATAL' = '\033[38;5;95m', - 'DEFAULT' = '\033[38;5;232m' + 'DEFAULT' = '\033[38;5;246m' )[[level]] if(is.null(prefix)){ - prefix <- '\033[38;5;232m' + prefix <- '\033[38;5;246m' } s <- paste(..., sep = sep) base::cat(prefix, s, "\033[39m", end, file = file, fill = fill, labels = labels, append = append, sep = '') diff --git a/cran-comments.md b/cran-comments.md index f0fdef48..44ff6a92 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,7 +1,7 @@ # Update logs (for R-cran only) -## 2021-12-02 -**Version 0.2.4 (current)** +## 2022-05-29 +**Version 0.2.5 (current)** Self check: 0 errors | 0 warnings | 1 notes @@ -10,6 +10,16 @@ checking installed package size ... NOTE installed size is 5.3Mb ``` +## 2021-12-02 +**Version 0.2.4 (passed)** + +Starting from this version, the package size will be greater than `5Mb`, which will trigger the check note. However, I can't reduce the size since most are from the `JavaScript` engine. + +``` +checking installed package size ... NOTE + installed size is 5.3Mb +``` + ## 2021-10-13 **Version 0.2.3 (passed)** diff --git a/man/template_subject.Rd b/man/template_subject.Rd index d00caca2..e0b521bd 100644 --- a/man/template_subject.Rd +++ b/man/template_subject.Rd @@ -12,7 +12,7 @@ \usage{ download_template_subject( subject_code = "N27", - url = "https://github.com/dipterix/threeBrain-sample/releases/download/1.0.0/N27.zip", + url, template_dir = default_template_directory() ) @@ -32,9 +32,9 @@ threebrain_finalize_installation( available_templates() } \arguments{ -\item{subject_code}{character with only letters and numbers (Important). Default is `N27`} +\item{subject_code}{character with only letters and numbers (Important); default is `N27`} -\item{url}{zip file address} +\item{url}{zip file address; must be specified if \code{subject_code} is not from the followings: \code{'bert'}, \code{'cvs_avg35'}, \code{'cvs_avg35_inMNI152'}, \code{'fsaverage'}, \code{'fsaverage_sym'}, or \code{'N27'}} \item{template_dir}{parent directory where subject's `FreeSurfer` folder should be stored}