├── .Rbuildignore ├── .gitignore ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── R └── nice.R ├── README.md ├── demo.gif ├── inst └── rstudio │ └── addins.dcf ├── littleboxes.Rproj └── man └── hello.Rd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | .Rproj.user 3 | .Rhistory 4 | .RData 5 | .Ruserdata 6 | ======= 7 | # History files 8 | .Rhistory 9 | .Rapp.history 10 | 11 | # Session Data files 12 | .RData 13 | 14 | # Example code in package build process 15 | *-Ex.R 16 | 17 | # Output files from R CMD build 18 | /*.tar.gz 19 | 20 | # Output files from R CMD check 21 | /*.Rcheck/ 22 | 23 | # RStudio files 24 | .Rproj.user/ 25 | 26 | # produced vignettes 27 | vignettes/*.html 28 | vignettes/*.pdf 29 | 30 | # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 31 | .httr-oauth 32 | 33 | # knitr and R markdown default cache directories 34 | /*_cache/ 35 | /cache/ 36 | 37 | # Temporary files created by R markdown 38 | *.utf8.md 39 | *.knit.md 40 | >>>>>>> 93ebf31009427a7e38c19ffe79f9e26fffaaccf6 41 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: littleboxes 2 | Type: Package 3 | Title: RStudio Addin - creates boxed in titles in an Rscript 4 | Version: 0.1.0 5 | Author: Vincent Guyader 6 | Maintainer: Vincent Guyader 7 | Description: Creates boxed in titles in an Rscript 8 | License: MIT 9 | LazyData: TRUE 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 ThinkRstat 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | exportPattern("^[[:alpha:]]+") 2 | -------------------------------------------------------------------------------- /R/nice.R: -------------------------------------------------------------------------------- 1 | dd <- function(x,l=60) { 2 | if (nchar(x) <= (l-10)) { # ptet pas -4 ici 3 | base <- (l - nchar(x) - 2)/2 4 | return(paste(c("####", rep(" ", floor(base)-3), x, rep(" ", 5 | ceiling(base)-3), "####"), collapse = "")) 6 | } 7 | 8 | s1 <- strsplit(x, "\\s")[[1]] 9 | 10 | # si s1 trop long on découpe arbitraitement au milieu 11 | if (length(s1)==1){ 12 | coupe <- nchar(s1)/2 13 | s1 <- c(substr(s1,1,coupe), substr(s1,1+coupe,nchar(s1))) 14 | } 15 | 16 | c(Recall( 17 | paste(s1[1:floor(length(s1)/2)], collapse = " "),l=l 18 | ), 19 | Recall( 20 | paste(s1[(1+floor(length(s1)/2)):length(s1)],collapse = " "),l=l 21 | ) 22 | ) 23 | } 24 | 25 | 26 | toutbeau <- function(x, l = 60) { 27 | # print(x) 28 | x <- gsub("\n", " ", x) 29 | x <- gsub("\t", " ", x) 30 | x <- gsub("^[# ]+", "", x) 31 | x <- gsub("[# =]+$", " ", x) 32 | x <- gsub(" $", " ", x) 33 | res <- paste(c("##%",rep("#", l-6),"%##"), collapse = "") 34 | res <- c(res, paste(c("#", rep(" ", l - 2), "#"), collapse = "")) 35 | res <- c(res, do.call(c, as.list(dd(x,l=l)))) 36 | res <- c(res, paste(c("#", rep(" ", l - 2), "#"), collapse = "")) 37 | res <- c(res, paste(c("##%",rep("#", l-6),"%##"), collapse = "")) 38 | res <- c(res, "") 39 | res 40 | res <- paste(res, collapse = "\n") 41 | return(res) 42 | } 43 | 44 | 45 | littleboxes <- function() { 46 | context <- rstudioapi::getActiveDocumentContext() 47 | for (sel in context$selection) { 48 | # print(sel) 49 | if (sel$text != "") { 50 | rstudioapi::modifyRange(sel$range, toutbeau(sel$text), 51 | context$id) 52 | break 53 | } else { 54 | 55 | lign <- context$selection[[1]]$range$start[["row"]] 56 | value <- context$contents[lign] 57 | range <- structure(list(start = structure(c(lign, 58 | 1), .Names = c("row", "column"), class = "document_position"), 59 | end = structure(c(lign, 77777), .Names = c("row", 60 | "column"), class = "document_position")), .Names = c("start", 61 | "end"), class = "document_range") 62 | 63 | if (value != "") { 64 | rstudioapi::modifyRange(range, toutbeau(value), 65 | context$id) 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # littleboxes 2 | RStudio Addin - creates boxed in titles in an Rscript 3 | 4 | ## Installation 5 | 6 | ```R 7 | # install.packages("devtools") 8 | devtools::install_github("ThinkR-open/littleboxes") 9 | 10 | # If you just want boxes without any tricks using Rstudio outline 11 | devtools::install_github("ThinkRstat/littleboxes",ref="simpleboxe") 12 | 13 | ``` 14 | ## Usage 15 | 16 | ![alt tag](https://raw.githubusercontent.com/ThinkRstat/littleboxes/master/demo.gif) 17 | 18 | 19 | 20 | ```R 21 | # write a sentence, place your cursor on the line and go to Addins > Little Boxes 22 | 23 | # Part One 24 | 25 | 1+1 26 | plot(iris) 27 | 28 | # Part Two 29 | lm(1~1) 30 | 31 | will be turned into: 32 | 33 | ##%######################################################%## 34 | # # 35 | #### Part One #### 36 | # # 37 | ##%######################################################%## 38 | 39 | 40 | 1+1 41 | plot(iris) 42 | 43 | ##%######################################################%## 44 | # # 45 | #### Part Two #### 46 | # # 47 | ##%######################################################%## 48 | 49 | lm(1~1) 50 | 51 | ``` 52 | [![Alt text](http://img.youtube.com/vi/yZnx-VbQ2bk/0.jpg)](https://www.youtube.com/watch?v=yZnx-VbQ2bk) 53 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VincentGuyader/littleboxes/617cd5e7de3bb044e709e8ade8047dbe980299e8/demo.gif -------------------------------------------------------------------------------- /inst/rstudio/addins.dcf: -------------------------------------------------------------------------------- 1 | 2 | Name: Little Boxes 3 | Description: Canned titles in #comments 4 | Binding: littleboxes 5 | Interactive: false 6 | -------------------------------------------------------------------------------- /littleboxes.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | -------------------------------------------------------------------------------- /man/hello.Rd: -------------------------------------------------------------------------------- 1 | \name{hello} 2 | \alias{hello} 3 | \title{Hello, World!} 4 | \usage{ 5 | hello() 6 | } 7 | \description{ 8 | Prints 'Hello, world!'. 9 | } 10 | \examples{ 11 | hello() 12 | } 13 | --------------------------------------------------------------------------------