Skip to content

Commit

Permalink
start on docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mdequeljoe committed Mar 27, 2019
1 parent 065398b commit 8832a0e
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 42 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Package: rdoc
Type: Package
Title: Pretty print Rd files to the console
Title: Print Colourised Rd Files in the Console.
Version: 0.1.0
Author: person("Matthew", "de Queljoe", email = "[email protected]", role = c("aut", "cre")
Maintainer: Matthew de Queljoe <[email protected]>
Description: More about what it does (maybe more than one line)
Use four spaces when indenting paragraphs within the Description.
Description: Extends tools::Rd2txt by adding text and colour formatting to Rd files
for terminal or console output.
License: GPL-3
Encoding: UTF-8
LazyData: true
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(rd_arguments)
export(rd_details)
export(rd_example)
export(rd_examples)
export(rd_question)
export(rd_usage)
export(rdoc)
export(rdoc_style)
Expand All @@ -13,3 +14,5 @@ import(crayon)
import(prettycode)
importFrom(R6,R6Class)
importFrom(tools,Rd2txt)
importFrom(utils,"?")
importFrom(utils,help)
50 changes: 38 additions & 12 deletions R/rdoc.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @importFrom utils help
rd_ <- function(which = NULL) {
function(topic,
package = NULL,
Expand Down Expand Up @@ -27,18 +28,30 @@ rd_ <- function(which = NULL) {
}
}

#' R docs
#' Colourised R documentation
#'
#' Refer to colourised \R docs in the console
#' Refer to colourised \R docs as terminal/console output. Provides a
#' replacement for \code{help}. A number of common section accessors are also
#' provided.
#' @family rd access
#' @aliases rd
#' @param topic \code{character(1)}, help topic
#' @param package \code{character(1)}, package of help topic. Defaults to NULL.
#' @param lib.loc \code{character(1)}, library location of package. Defaults to null.
#' @param package \code{character(1)}, package of help topic. Defaults to
#' \code{NULL}
#' @param lib.loc \code{character(1)}, library location of package. Defaults to
#' \code{NULL}
#'
#' @details The manner in which content is outputted depends on where it is
#' being used. If used from a terminal the contents will be outputted via
#' \code{file.show}. If used from a console the output will be printed to
#' screens by sections unless this has been disabled via
#' \code{options(rdoc.by_section = FALSE)}. In this case pressing any key will
#' print out the next section. Exiting out early is possible with the 'q' key.
#' Color support is checked via \code{crayon::has_color()}.
#'
#' @examples \dontrun{
#'
#' rd("rd", by_section = FALSE)
#' rd("rd")
#' rd(grepl)
#' rd_example("min")
#' rd_usage(substr)
Expand Down Expand Up @@ -68,7 +81,10 @@ rd_example <- rd_("examples")
#' @export
rd_examples <- rd_example


#' rd ?
#' @inherit rd details
#' @importFrom utils ?
#' @export
rd_question <- function(type, topic) {
type <- substitute(type)
topic <- substitute(topic)
Expand All @@ -92,21 +108,31 @@ rd_question <- function(type, topic) {
d$show()
}

#' rdoc
#' rdoc-style \code{?} replacement for \code{utils::`?`}
#' Colourised R documentation
#'
#' rdoc replacements for \code{?} and \code{help}
#'
#' @details
#' Calling \code{rdoc()} will override \code{utils::`?`}
#' Calling \code{rdoc()} will override \code{utils::`?`} with \code{rd_question}
#' and \code{utils::help} with \code{rd}
#' These replacements can be unset by calling \code{rdoc()} once more.
#' @examples \dontrun{
#'
#' rdoc::rdoc()
#' ?help
#' rdoc::rdoc()
#' ?help
#' }
#'
#' @export
rdoc <- function(){

if ("rdoc" %in% searchpaths()){
base::detach("rdoc")
detach("rdoc")
return(invisible(NULL))
}

e <- new.env()
e$`?` <- rd_question
base::attach(e, name = "rdoc", warn.conflicts = FALSE)
attach(e, name = "rdoc", warn.conflicts = FALSE)
}

45 changes: 23 additions & 22 deletions man/rd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions man/rd_question.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 15 additions & 5 deletions man/rdoc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8832a0e

Please sign in to comment.