├── .Rbuildignore ├── .gitignore ├── .travis.yml ├── DESCRIPTION ├── NAMESPACE ├── NEWS.md ├── R └── roxygen2_block.R ├── README.Rmd ├── README.md ├── inst └── rstudio │ └── addins.dcf ├── man └── roxygen2_block.Rd └── roxygen2Comment.Rproj /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^README\.Rmd$ 4 | ^README-.*\.png$ 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # History files 2 | .Rhistory 3 | .Rapp.history 4 | 5 | # Session Data files 6 | .RData 7 | 8 | # Example code in package build process 9 | *-Ex.R 10 | 11 | # RStudio files 12 | .Rproj.user/ 13 | 14 | # produced vignettes 15 | vignettes/*.html 16 | vignettes/*.pdf 17 | 18 | # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 19 | .httr-oauth 20 | .Rproj.user 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: r 2 | cache: packages 3 | 4 | notifications: 5 | email: 6 | on_success: change 7 | on_failure: change 8 | 9 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: roxygen2Comment 2 | Type: Package 3 | Title: Rstudio roxygen2 addin 4 | Version: 0.1.1 5 | Date: 2016-04-17 6 | Authors@R: person(given="Colin", family="Gillespie", 7 | email="csgillespie@gmail.com", role = c("aut", "cre")) 8 | Maintainer: Colin Gillespie 9 | Description: An RStudio addin for adding and remove roxygen2 comments. 10 | License: GPL-2 | GPL-3 11 | LazyData: TRUE 12 | URL: https://github.com/csgillespie/roxygen2Comment 13 | BugReports: https://github.com/csgillespie/roxygen2Comment/issues 14 | Imports: 15 | rstudioapi(>= 0.5) 16 | Suggests: knitr 17 | RoxygenNote: 7.1.1 18 | VignetteBuilder: knitr 19 | Encoding: UTF-8 20 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(roxygen2_block) 4 | import(rstudioapi) 5 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | ## Version 0.1.1 2 | * Bug fix. Missing import. 3 | 4 | ## Version 0.1 5 | * Initial release. 6 | -------------------------------------------------------------------------------- /R/roxygen2_block.R: -------------------------------------------------------------------------------- 1 | #' Adds an roxygen2 comment block 2 | #' 3 | #' Adds an roxygen2 comment block 4 | #' @import rstudioapi 5 | #' @export 6 | roxygen2_block = function() { 7 | location = rstudioapi::getActiveDocumentContext() 8 | ## Get the row number 9 | 10 | r_start = location$selection[[1]]$range$start[1] 11 | r_end = location$selection[[1]]$range$end[1] 12 | r = r_start:r_end 13 | 14 | line = location$contents[r_start] 15 | 16 | # If roxygen2 block remove #' 17 | # If not remove, add #' 18 | comment = grep( 19 | "^#'\\s?" # line starts with "#'", has no or one trailing whitespace 20 | , line 21 | , value = TRUE 22 | ) 23 | 24 | is_roxy2 = length(comment > 0) 25 | if(is_roxy2) { 26 | rng = Map( 27 | c 28 | , Map(c, r, 1) 29 | , Map(c, r, ifelse(grepl("\\s", comment), 4, 3)) # if applicable, strip trailing whitespace 30 | ) 31 | modifyRange(rng, "") 32 | } else { 33 | pos = Map(c, r_start:r_end, 1) 34 | insertText(pos, "#' ") 35 | } 36 | } 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: 3 | md_document: 4 | variant: markdown_github 5 | --- 6 | 7 | 8 | 9 | ```{r, echo = FALSE} 10 | knitr::opts_chunk$set( 11 | collapse = TRUE, 12 | comment = "#>", 13 | fig.path = "README-" 14 | ) 15 | ``` 16 | 17 | 18 | # An RStudio addin for roxygen2 code blocks 19 | [![Build Status](https://travis-ci.org/csgillespie/roxygen2Comment.png?branch=master)](https://travis-ci.org/csgillespie/roxygen2Comment) 20 | [![CRAN](http://www.r-pkg.org/badges/version/roxygen2Comment)](http://cran.rstudio.com/package=roxygen2Comment) 21 | 22 | RStudio addins let you execute a bit of R code or a Shiny app through the RStudio IDE, 23 | either via the Addins dropdown menu or with a keyboard shortcut. This package contains an RStudio addin for commenting roxygen2 code. 24 | 25 | This package can be installed via 26 | ```{r eval=FALSE} 27 | devtools::install_github("csgillespie/roxygen2Comment") 28 | ``` 29 | 30 | ## Running addins 31 | 32 | After installing the package, the _Addins_ menu toolbar will be populated with the 33 | new, exported addin. The addin will work exactly like the RStudio keyboard 34 | shortcut for commenting. 35 | 36 | * If you execute the addin on standard code, it will add `#'` to the start of the line. 37 | * If you execute the addin on an roxygen2 comment, it will remove `#'` 38 | 39 | ## Manage your addins 40 | 41 | See my other [package](https://github.com/csgillespie/addinmanager) for 42 | conviently adding and removing RStudio addins. 43 | 44 | 45 | ## Other information 46 | 47 | * If you have any suggestions or find bugs, please use the github issue tracker. 48 | * Feel free to submit pull requests for new addins. 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | An RStudio addin for roxygen2 code blocks 3 | ========================================= 4 | 5 | [![Build Status](https://travis-ci.org/csgillespie/roxygen2Comment.png?branch=master)](https://travis-ci.org/csgillespie/roxygen2Comment) [![CRAN](http://www.r-pkg.org/badges/version/roxygen2Comment)](http://cran.rstudio.com/package=roxygen2Comment) 6 | 7 | RStudio addins let you execute a bit of R code or a Shiny app through the RStudio IDE, either via the Addins dropdown menu or with a keyboard shortcut. This package contains an RStudio addin for commenting roxygen2 code. 8 | 9 | This package can be installed via 10 | 11 | ``` r 12 | devtools::install_github("csgillespie/roxygen2Comment") 13 | ``` 14 | 15 | Running addins 16 | -------------- 17 | 18 | After installing the package, the *Addins* menu toolbar will be populated with the new, exported addin. The addin will work exactly like the RStudio keyboard shortcut for commenting. 19 | 20 | - If you execute the addin on standard code, it will add `#'` to the start of the line. 21 | - If you execute the addin on an roxygen2 comment, it will remove `#'` 22 | 23 | Manage your addins 24 | ------------------ 25 | 26 | See my other [package](https://github.com/csgillespie/addinmanager) for conviently adding and removing RStudio addins. 27 | 28 | Other information 29 | ----------------- 30 | 31 | - If you have any suggestions or find bugs, please use the github issue tracker. 32 | - Feel free to submit pull requests for new addins. 33 | -------------------------------------------------------------------------------- /inst/rstudio/addins.dcf: -------------------------------------------------------------------------------- 1 | Name: roxygen2 comment block 2 | Description: Add an roxygen2 comment block 3 | Binding: roxygen2_block 4 | Interactive: false 5 | -------------------------------------------------------------------------------- /man/roxygen2_block.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/roxygen2_block.R 3 | \name{roxygen2_block} 4 | \alias{roxygen2_block} 5 | \title{Adds an roxygen2 comment block} 6 | \usage{ 7 | roxygen2_block() 8 | } 9 | \description{ 10 | Adds an roxygen2 comment block 11 | } 12 | -------------------------------------------------------------------------------- /roxygen2Comment.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: knitr 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace 22 | --------------------------------------------------------------------------------