Skip to content

Commit

Permalink
feat: Implement support for R including tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed Jun 23, 2019
1 parent 871acbc commit 121e7de
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ go on coding!
- [x] Ruby ([YARD](https://www.rubydoc.info/gems/yard/file/docs/Tags.md))
- [x] Scala ([ScalaDoc](https://docs.scala-lang.org/style/scaladoc.html))
- [x] Kotlin ([KDoc](https://kotlinlang.org/docs/reference/kotlin-doc.html))
- [ ] R ([R style guide](https://style.tidyverse.org/documentation.html))
- [x] R ([Roxygen2](https://github.com/klutometis/roxygen))
- [ ] C++ ([CPPDoc](http://www.edparrish.net/common/cppdoc.html#comment))
- [ ] Haskell ([Haddock](https://www.haskell.org/haddock/doc/html/ch03s02.html))
- [ ] Idris ([IdrisDocs](http://docs.idris-lang.org/en/latest/reference/documenting.html))
Expand Down
57 changes: 57 additions & 0 deletions ftplugin/r.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
" ==============================================================================
" The R documentation should follow the 'Roxygen2' conventions.
" see https://github.com/klutometis/roxygen
" ==============================================================================

let s:save_cpo = &cpoptions
set cpoptions&vim

let b:doge_patterns = []

" ==============================================================================
" Matches regular functions.
" ==============================================================================
"
" Matches the following scenarios:
"
" myFunc.default <- function(
" p1,
" p2.sub1 = FALSE,
" p3.sub1 = 20,
" p4.sub1 = 1/15,
" ...
" ) {
" # ...
" }

" myFunc = function(
" p1 = TRUE, p2_sub1= TRUE, p3 = FALSE,
" p4 = 'libs', p5 = NULL, ..., p7 = 'default',
" p8 = c('lorem', 'ipsum+dor', 'sit', 'amet'),
" p9 = TRUE, p10 = list(), p11 = TRUE
" ) {
" # ...
" }
call add(b:doge_patterns, {
\ 'match': '\m^\([[:alnum:]_.]\+\)\s*\%(=\|<-\)\s*function\s*(\(.\{-}\))\s*{',
\ 'match_group_names': ['funcName', 'parameters'],
\ 'parameters': {
\ 'match': '\m\([[:alnum:]_]\+\%(.\%([[:alnum:]_]\+\)\)*\)\%(\s*=\s*\%([[:alnum:]_]\+(.\{-})\|[^,]\+\)\)\?',
\ 'match_group_names': ['name'],
\ 'format': ['@param', '{name}', 'TODO'],
\ },
\ 'comment': {
\ 'insert': 'above',
\ 'template': [
\ "#' TODO",
\ "#'",
\ "#' {parameters}",
\ "#'",
\ "#' @export",
\ "#'",
\ ],
\ },
\})

let &cpoptions = s:save_cpo
unlet s:save_cpo
65 changes: 65 additions & 0 deletions playground/test.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Functions
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

#' TODO
#'
#'
#' @export
#'
myFunc = function() {
# ...
}

#' TODO
#'
#'
#' @export
#'
myFunc <- function() {
# ...
}


#' TODO
#'
#' @param p1 TODO
#' @param p2.sub1 TODO
#' @param p3.sub1 TODO
#' @param p4.sub1 TODO
#'
#' @export
#'
myFunc.default <- function(
p1,
p2.sub1 = FALSE,
p3.sub1 = 20,
p4.sub1 = 1/15,
...
) {
# ...
}

#' TODO
#'
#' @param p1 TODO
#' @param p2_sub1 TODO
#' @param p3 TODO
#' @param p4 TODO
#' @param p5 TODO
#' @param p7 TODO
#' @param p8 TODO
#' @param p9 TODO
#' @param p10 TODO
#' @param p11 TODO
#'
#' @export
#'
myFunc = function(
p1 = TRUE, p2_sub1= TRUE, p3 = FALSE,
p4 = 'libs', p5 = NULL, ..., p7 = 'default',
p8 = c('lorem', 'ipsum+dor', 'sit', 'amet'),
p9 = TRUE, p10 = list(), p11 = TRUE
) {
# ...
}
76 changes: 76 additions & 0 deletions test/filetypes/r/functions.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# ==============================================================================
# Functions without parameters.
# ==============================================================================
Given r (functions without parameters):
myFunc = function() {
# ...
}

myFunc <- function() {
# ...
}

Do (trigger doge):
\<C-d>
:10\<CR>
\<C-d>

Expect r (generated comments with nothing but the text 'TODO' and @export tag):
#' TODO
#'
#'
#' @export
#'
myFunc = function() {
# ...
}

#' TODO
#'
#'
#' @export
#'
myFunc <- function() {
# ...
}

# ==============================================================================
# Functions with parameters.
# ==============================================================================
Given r (function with parameters):
myFunc = function(
p1 = TRUE, p2_sub1= TRUE, p3 = FALSE,
p4 = 'libs', p5 = NULL, ..., p7 = 'default',
p8 = c('lorem', 'ipsum+dor', 'sit', 'amet'),
p9 = TRUE, p10 = list(), p11 = TRUE
) {
# ...
}

Do (trigger doge):
\<C-d>

Expect r (generated comment with @param and @export tags):
#' TODO
#'
#' @param p1 TODO
#' @param p2_sub1 TODO
#' @param p3 TODO
#' @param p4 TODO
#' @param p5 TODO
#' @param p7 TODO
#' @param p8 TODO
#' @param p9 TODO
#' @param p10 TODO
#' @param p11 TODO
#'
#' @export
#'
myFunc = function(
p1 = TRUE, p2_sub1= TRUE, p3 = FALSE,
p4 = 'libs', p5 = NULL, ..., p7 = 'default',
p8 = c('lorem', 'ipsum+dor', 'sit', 'amet'),
p9 = TRUE, p10 = list(), p11 = TRUE
) {
# ...
}

0 comments on commit 121e7de

Please sign in to comment.