1 2show_html <- function(x,output=NULL,...){ 3 4 ht <- format_html(x,...) 5 6 if(interactive()){ 7 # Test whether running under RStudio 8 isRStudio <- Sys.getenv("RSTUDIO") == "1" 9 if(isRStudio) 10 deflt.output <- "file-show" 11 else 12 deflt.output <- "browser" 13 } 14 else 15 deflt.output <- "stdout" 16 17 if(missing(output)) 18 output <- getOption("html_viewer",deflt.output) 19 20 if(mode(output)=="character") 21 output <- match.arg(output,c("stdout","browser","file-show")) 22 else if(!is.function(output)) 23 stop("'output' should be either a character string of a function") 24 25 if(is.function(output)){ 26 27 tf <- tempfile() 28 tf <- paste0(tf,".html") 29 cat(ht,file=tf) 30 31 output(tf) 32 } 33 else if(nzchar(Sys.getenv("JPY_PARENT_PID"))){ 34 ## Inside Jupyter 35 return(html_div(ht)) 36 } 37 else if(output=="stdout") cat(ht) 38 else { 39 40 tf <- tempfile() 41 tf <- paste0(tf,".html") 42 cat(ht,file=tf) 43 44 if(output=="file-show") 45 file.show(tf,title=deparse(substitute(x))) 46 else 47 browseURL(tf) 48 } 49 50} 51 52write_html <- function(x,file,...) 53 cat(format_html(x,...),file=file) 54 55format_html <- function(x,...) 56 UseMethod("format_html") 57 58 59 60spltDec <- function(x,at="."){ 61 y <- strsplit(x,at,fixed=TRUE) 62 y1 <- sapply(y,"[",1) 63 y3 <- sapply(y,"[",2) 64 y1[is.na(y1)] <- "" 65 y3[is.na(y3)] <- "" 66 y2 <- ifelse(grepl("[[:digit:]]+",y3),at,"") 67 y <- rbind(y1,y2,y3) 68 as.vector(y) 69} 70 71 72 73upd_vect <- function(x,...){ 74 y <- c(...) 75 n <- names(y) 76 x[n] <- y 77 x 78} 79