formatForStackOverflow: Run and format R code to StackOverflow submission ready

Description Usage Arguments Value Author(s) Examples

Description

Runs the R code, captures both code and output and prints such that code and output are readily copied into an Stack Overflow post or answer. I.e. it prefixes four spaces and (optinally) comments output.

Usage

1
formatForStackOverflow(user_code, comment_eval = TRUE, file = "")

Arguments

user_code

A character of length 1 of user code to run and format.

comment_eval

logical. If TRUE output is prefixed with a comment.

file

A path to a file to write the output to. The default prints to console.

Value

Prints to console or file a ready-to-copy to Stack Overflow formatted code and output.

Author(s)

Anders Ellern Bilgrau <anders.ellern.bilgrau (at) gmail.com>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
formatForStackOverflow("
  myfunc <- function(x) {
    return(c(mean=mean(x), med=median(x)))
  }
  
  # A comment
  n <- 100
  myfunc(rnorm(n))
  
  sapply(mtcars, myfunc) # inline comment
  
  print(mtcars)
")

AEBilgrau/Bmisc documentation built on May 5, 2019, 11:28 a.m.