## Sparse matrices

(흔히 넓은 지역에 분포된 정도가) 드문, (밀도가) 희박한 sparse  matrix 희소 행렬 :  행렬 내부의 원소가 거의 0이고  실제 값이 들어간 건 몇 개 안 되는 행렬입니다 In numerical analysis and computer science, a sparse matrix or sparse array is a matrix in which most of the elements are zero. By contrast, if most of Read more…

## try catch finally in r

tryCatch({       data.oac.null <- rbind(data.oac.null, data.oac[[j]][[m-i]])       cat(“sheet”,m-i, “”)       }, error = function(e){cat(“ERROR :”,conditionMessage(e), “\n”)} http://mazamascience.com/WorkingWithData/?p=912 result = tryCatch({     expr }, warning = function(w) {     warning-handler-code }, error = function(e) {     error-handler-code }, finally = {     cleanup-code }

## protect(): protection stack overflow

https://www.researchgate.net/post/error_protect_protection_stack_overflow_in_R‘ > dd %>% dim [1] 12 39319 to change the data from data.frame to matrix form. ========================================================== You probably have to set –max-ppsize See http://stat.ethz.ch/R-manual/R-devel/library/base/html/Memory.html You’ll also find some discussions about this on StackOverflow. See http://stackoverflow.com/questions/28728774/how-to-set-max-ppsize-in-r for instance   ================================ ‘memory.limit’ function recommended by Maurizio may work for some users, but it is Read more…

## tstrsplit

equivalent to transpose(strsplit(…))     > strsplit(“A text I want to display with spaces”, NULL) [[1]] [1] “A” ” ” “t” “e” “x” “t” ” ” “I” ” ” “w” “a” “n” “t” ” ” “t” “o” ” ” “d” “i” “s” “p” “l” “a” “y” ” ” “w” “i” “t” Read more…

## identical vs all.equal

https://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal 숫자 비교시, 아주아주 정확할 필요가 없다면 identical() 보다는 all.equal()을 사용하는 편이 정신건강에 좋다. > i <- 0.1 > i <- i + 0.05 > identical(i, 0.15) [1] FALSE > identical(round(i,1), 0.15) [1] FALSE > identical(round(i,2), 0.15) [1] TRUE > all.equal(i, 0.15) [1] TRUE > i <- 0.1 > i Read more…

## webAPI plumber

http://blog.expresspixel.com/creating-a-web-api-for-r/   https://www.rplumber.io/ https://github.com/trestletech/plumber https://www.rplumber.io/docs There’s 3 options for you to use to build a web based API. 1. Shiny, 2. Deployrand 3. Plumber. prediction.R #* @get /prediction function(){ return(“Hello World”) } main.R #!/usr/bin/env Rscript library(plumber) r <- plumb(“prediction.R”) r\$run(host=”0.0.0.0″, port=8000)   ~/sixx/webAPI\$ Rscript main.R Starting server to listen on port 8000   Read more…

## data.table

> A <- as.data.frame(a) > A a 1 NA 2 TRUE 3 FALSE 4 NA > AA <- as.data.table(A) > AA[,(nn):=NULL] Error in eval(lhs, parent.frame(), parent.frame()) : object ‘nn’ not found > AA[,(nn):=NA] Error in eval(lhs, parent.frame(), parent.frame()) : object ‘nn’ not found > AA[,.(nn):=NA] Error in eval(lhs, parent.frame(), Read more…

## CSS with regex for id

https://stackoverflow.com/questions/42497352/css-with-regex-for-id <div id=”sections”> <div id=”s10″>one</div> <div id=”s2″>two</div> <div id=”s30″>three</div> <div id=”t1″>four</div> </div>  id\$=’0′  는 id가 0으로 끝나는 거  id^=’s’  는 id 가 s로 시작하는 거  #sections div[id^=’s.*0′] { color: red; } #sections div[id\$=’0′][id^=’s’] { color: red; }   https://developer.mozilla.org/pl/docs/Web/CSS/Attribute_selectors /* <a> elements with a title attribute */ a[title] { color: Read more…

## popup size

g_fun.R bsModalNoFoot – size bsModalNoFoot <- function (id, title, trigger, …, easyClose = FALSE, size) { if (!missing(size)) { if (size == “large”) { size = “modal-lg” } else if (size == “small”) { size = “modal-sm” } size <- paste(“modal-dialog”, size) } else { size <- “modal-dialog” } bsTag Read more…

## shinyjs run javascript

https://www.jqueryscript.net/demo/Animated-Circles-Loading-Spinner-jQuery-g-spinner/ src\css\gspinner.css src\js\g-spinner.js How to use it: 1. Load the minified versions of the g-spinner plugins JS & CSS in your webpage which has jQuery library loaded. <link rel=”stylesheet” href=”gspinner.min.css”> <script src=”jquery.min.js”></script> <script src=”g-spinner.min.js”></script> 2. Create a DIV element where we want to insert the loading indicator into: <div id=”loader”> </div> 3. We need a Read more…

## Terms() Formula()

https://www.datacamp.com/community/tutorials/r-formula-tutorial

## rspm (rstudio package manager)

https://www.rstudio.com/products/package-manager/ repository management server to organize and centralize R packages across your team Get offline access to CRAN, automate CRAN syncs, share local packages, restrict package access, find packages across repositories http://docs.rstudio.com/rspm/admin/quickstarts.html http://docs.rstudio.com/rspm/admin/ We currently only provide a pre-built binary for the 64-bit architecture. Execute the following commands in a Read more…

## Error: stat_smooth requires the following missing aesthetics

geom_smooth(stat_smooth)에 상속된 aes()가 잘못됐을 경우 발생  http://stulp.gmw.rug.nl/ggplotworkshop/twocontinuousvariables.html  ::  12.1.1.1 inherite.aes ### 동력전달타입(drv)별 배기량(displ)이 도심 주행연비(cty)에 미치는 영향 p <- mpg %>% ggplot(aes(displ, cty, color=drv)) p + geom_point() + geom_smooth(method=”lm”, se=F) ### same above —- p + geom_point(inherit.aes=T) + geom_smooth(method=”lm”, se=F, inherit.aes=T) p + geom_point( data=mpg, aes(x=displ, y=cty, colour=drv)) + geom_smooth(data=mpg, Read more…

## facet_wrap ylim

https://chrischizinski.github.io/rstats/using_geom_blank/ https://stackoverflow.com/questions/18046051/setting-individual-axis-limits-with-facet-wrap-and-scales-free-in-ggplot2 set.seed(666) foo.dat<-rbind(data.frame(group=”A”, x = runif(50), y=rnorm(50,mean=5)), data.frame(group=”B”, x = runif(50), y=rnorm(50,mean=5,sd=3)+20), data.frame(group=”C”, x = runif(50), y=rnorm(50,mean=5,sd=5)+30)) ## Plot it in ggplot ggplot() + geom_point(data=foo.dat,aes(x=x,y=y,colour=group),size=4) + facet_wrap(~group,scales=”free_y”) + ## using scales=”free_y” allows the y-axis to vary while keeping x-axis constant among plots theme_bw() ggplot() + geom_point(data = foo.dat, aes(x Read more…

## UIOutput level plot test

library(shinyWidgets) #draw_data <- readRDS(“/home/sixx/d2cm/1.RCodes/4.Etc/9.sixx/draw_data.rds”) init_env0 <- function(){ env <- new.env() env\$dd <- NULL return(env) } env6 <- init_env0() server <- function(input,output, session){ uFunc_draw_plot<- function(dd, selected_col, val_limit){ p <- dd %>% ggplot(aes_string(x=”sec”, y=”val”, group=”subid”, color=selected_col)) + coord_cartesian(ylim=val_limit) + geom_point() + geom_line() output\$O_plt_main <- renderPlot({ return(p) }) } observeEvent(input\$I_btn_load_make_dd, { if Read more…