Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added soanswer and modified readClip #26

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e4c9b48
readSO updated with readSOfwf
mrdwab Apr 24, 2013
8a2dda1
deleted residual code
mrdwab Apr 24, 2013
f5da812
Create SOanswer.R
richierocks Dec 1, 2014
341f88c
Merge pull request #1 from richierocks/master
mrdwab Dec 1, 2014
3b7fcaf
Update SOanswer.R
richierocks Dec 2, 2014
118b62e
Merge pull request #2 from richierocks/master
mrdwab Dec 2, 2014
d2e304e
Update SOanswer.R
richierocks Dec 2, 2014
de319db
Update DESCRIPTION
richierocks Dec 2, 2014
e56f5f8
Update SOanswer.R
richierocks Dec 2, 2014
3228c0a
Merge pull request #4 from richierocks/master
mrdwab Dec 2, 2014
7e2687a
added Richard Cotton to authors
mrdwab Dec 2, 2014
ce6eded
added RC
mrdwab Dec 2, 2014
0307ad2
updating to sebastian's version
mrdwab May 30, 2015
c33b652
man pages updates
mrdwab May 30, 2015
2cd41ea
new versions
mrdwab May 30, 2015
c350d1e
readclip updates
mrdwab May 30, 2015
9aede59
author updates
mrdwab May 30, 2015
298764c
README updated with function listing
mrdwab Feb 28, 2016
70fc555
Added examples
mrdwab Feb 28, 2016
78d20c0
Added examples
mrdwab Feb 28, 2016
b7d7d70
checkboxes don't work
mrdwab Feb 28, 2016
118fb78
pipe changed for xclip
mrdwab Feb 28, 2016
df73723
limitations added
mrdwab Feb 28, 2016
cda4628
Added a link to wakefield
mrdwab Feb 28, 2016
4da774c
consolidate clipboard to single file
mrdwab Feb 28, 2016
8d93d4a
roxygen updates
mrdwab Feb 28, 2016
7658f41
add 'solast'
brodieG Mar 21, 2016
abeb55b
actually implement 'clip' option
brodieG Mar 21, 2016
cb006f0
Merge pull request #5 from brodieG/last
mrdwab Mar 21, 2016
053a53b
added brpdoe to description
mrdwab Mar 21, 2016
cef7d55
added Brodie and `solast`.
mrdwab Mar 21, 2016
19f7017
stack overflow
mrdwab Mar 21, 2016
8439960
version change and solast added to readme
mrdwab Mar 21, 2016
330de72
added docs
mrdwab Jun 19, 2020
47e8d71
Docs
mrdwab Jun 19, 2020
a9bf83b
Updated readme
mrdwab Jun 19, 2020
a5834db
updated roxygen
mrdwab Jun 19, 2020
8e331f5
soread modified
mrdwab Jun 19, 2020
0d07e51
rebuilt documentation
mrdwab Jun 19, 2020
b81eb27
URL was in the wrong place
mrdwab Jun 19, 2020
001e54b
rebuilt index
mrdwab Jun 19, 2020
e6a3f8f
Correcte documentation for soread
mrdwab Jun 19, 2020
1573324
Updated readme
mrdwab Jun 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
^.*\.Rproj$
^\.Rproj\.user$
^_pkgdown\.yml$
^docs$
^pkgdown$
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@

# Example code in package build process
*-Ex.R

29 changes: 13 additions & 16 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
Package: oveRflow
Version: 0.1-0
Date: 2013-03-24
Package: overflow
Version: 0.2-4
Date: 2020-06-19
Title: Utility functions for answering R question on StackOverflow
Authors@R: c(person("Sebastian", "Campbell", role = c("aut", "cre"),
Authors@R: c(person("Sebastian", "Campbell", role = "aut",
email="[email protected]"),
person("Ananda", "Mahto", role="aut",
person("Ananda", "Mahto", role=c("aut", "cre"),
email="[email protected]"),
person("Julien", "Barnier", role="aut",
email="[email protected]"),
person("Tyler", "Rinker", role="ctb"))
Author: Sebastian Campbell, Ananda Mahto, Julien Barnier
Maintainer: Sebastian Campbell <[email protected]>
person("Tyler", "Rinker", role="aut"),
person("Richard", "Cotton", role="aut"),
person("Brodie", "Gaslam", role="aut"))
Description: On StackOverflow, there are several tasks which are performed
repeatedly including temporarily installing a package and copying code into
an R session. This package automates some of these processes, making
answering questions easier.
License: GPL-3
URL: http://github.com/sebastian-c/oveRflow
BugReports: http://github.com/sebastian-c/oveRflow/issues
Collate:
'readSO.R'
'tmp_install_packages.R'
'readClip.R'
'writeClip.R'
'SOdput.R'
URL: http://mrdwab.github.io/overflow-mrdwab, https://github.com/mrdwab/overflow-mrdwab
BugReports: https://github.com/mrdwab/overflow-mrdwab/issues
RoxygenNote: 7.1.0
Suggests: testthat
Encoding: UTF-8
20 changes: 17 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
export(readSO)
export(SOdput)
export(tmp_install_packages)
# Generated by roxygen2: do not edit by hand

S3method(sotrunc,data.frame)
S3method(sotrunc,default)
S3method(sotrunc,list)
S3method(sotrunc,matrix)
export(lastcall)
export(soanswer)
export(sodput)
export(solast)
export(sopkgs)
export(sorandf)
export(sorandf_add)
export(sorandf_reset)
export(soread)
export(sotrunc)
importFrom(utils,capture.output)
11 changes: 0 additions & 11 deletions NEWS

This file was deleted.

29 changes: 29 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# overflow 0.2-4

* Modified `soread` to allow skipping lines after header, for example when
using with outpt from a `tibble`.

# overflow 0.2-3

* `solast` added to capture the output from `.Last.value` along with the last
expression from the history.

# overflow 0.2-1

* Added `sorandf` for creating random datasets.

# overflow 0.2-0

* Renamed package from 'oveRflow' to 'overflow'
* Renamed function `SOread`, `SOdput` and `tmp_install_packages to `soread` and
`sodput` and `sopkgs` for easier use.
* New function: SOdput - Sends `dput` to clipboard with assignment operator.
* readSO now strips out ## comments and leading whitespace.
* Bugfix - tmp_install_packages no longer overwrites libraries which are not
the base and user libraries.
* New function: tmp_install_packages - installs packages to a temporary library.
* Bugfix - readSO now works on Mac.

# overflow 0.1-0

* New function: readSO - reads in data from StackOverflow.
75 changes: 75 additions & 0 deletions R/clipboard.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#' Read Clipboard Regardless of OS
#'
#' Different operating systems have different ways of handling the clipboard.
#' Given the frequency with which text is copied to the clipboard to place in
#' an answer on StackOverflow, this utility is provided.
#'
#' @return character string containing text on the clipboard.
#'
readClip <- function() {
OS <- Sys.info()["sysname"]
cliptext <- switch(
OS,
Darwin = {
con <- pipe("pbpaste")
text <- readLines(con)
close(con)
text
},
Windows = readClipboard(),
Linux = {
if (Sys.which("xclip") == "") {
mess <- c("Clipboard on Linux requires 'xclip'. Try using:",
"sudo apt-get install xclip")
message(paste(mess, collapse = "\n"))
}
con <- pipe("xclip -o -selection clipboard")
text <- readLines(con = con)
close(con)
text
},
stop("Reading from clipboard not yet supported on your OS"))
cliptext
}

#' Write to Clipboard on Multiple OSes
#'
#' This function works on Windows, Mac and Linux. It copies a
#' character string or vector of characters to the clipboard and interprets
#' a vector of characters as one character with each element being newline
#' separated. If using Linux, xclip is used as the clipboard. So for the
#' function to work, xclip must be installed.
#'
#' @param object character. Character to be copied to the clipboard
#'
#' @return Returns nothing to R. Returns character string to the clipboard
#'
#' @details If using Linux, xclip will be used as the clipboard. To paste from
#' xclip, either use middle click or the command \code{xclip -o} in the shell.
#'
writeClip <- function(object) {
OS <- Sys.info()["sysname"]
if(!(OS %in% c("Darwin", "Windows", "Linux"))) {
stop("Copying to clipboard not yet supported on your OS")
}
switch(
OS,
Darwin = {
con <- pipe("pbcopy", "w")
writeLines(object, con=con)
close(con)
},
Windows = writeClipboard(object, format = 1),
Linux = {
if (Sys.which("xclip") == "") {
if (Sys.which("xclip") == "") {
mess <- c("Clipboard on Linux requires 'xclip'. Try using:",
"sudo apt-get install xclip")
message(paste(mess, collapse = "\n"))
}
}
con <- pipe("xclip -selection clipboard -i", open = "w")
writeLines(object, con=con)
close(con)
})
}
12 changes: 12 additions & 0 deletions R/package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#' Helper functions for answering R StackOverflow questions
#'
#' This package is focused on providing helper functions to answer StackOverflow
#' questions. It includes functions to transfer code and create random datasets.
#'
#' @docType package
#' @name overflow-package
#' @aliases overflow
#'
#' @author Sebastian Campbell, Ananda Mahto, Julien Barnier, Tyler Rinker

NULL
23 changes: 0 additions & 23 deletions R/readClip.R

This file was deleted.

45 changes: 45 additions & 0 deletions R/soanswer.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#' Turn an R expression into an SO answer
#'
#' Parrot the input expression and append the output with knitr-style comments,
#' all as markdown. \code{soanswer} changes the output for a single expression.
#' @param expr An R expression.
#' @param in_task_callback A logical value. Not intended for direct use.
#' @return Markdown output is printed to the console, written to the clipboard
#' and silently returned as a \code{noquote} character vector.
#' @author Richard Cotton
#' @seealso \code{\link[base]{addTaskCallback}}
#' @examples
#' # Output for various types, explicitly calling soanswer
#' soanswer(sin(2 * pi))
#' soanswer(sleep)
#' soanswer(message("A message!"))
#' soanswer(warning("A warning!"))
#' soanswer(stop("An error!"))
#' @importFrom utils capture.output
#' @export soanswer
soanswer <- function(expr, in_task_callback = FALSE)
{
input_lines <- noquote(
paste0(
" ",
if(in_task_callback)
{
deparse(expr)
} else
{
deparse(substitute(expr))
}
)
)
output <- tryCatch(
utils::capture.output(print(if(in_task_callback) eval(expr) else expr)),
message = function(m) substring(m$message, 1, nchar(m$message) - 1),
warning = function(w) c("Warning message:", w$message),
error = function(e) paste("Error:", e$message)
)
output_lines <- noquote(paste0(" ## ", output))
lines <- c(input_lines, output_lines)
cat(lines, sep = "\n")
writeClip(lines)
invisible(lines)
}
10 changes: 5 additions & 5 deletions R/SOdput.R → R/sodput.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
#' In several cases, you may want to give a sample dataset. \code{dput} is a great tool for doing so. This tool takes
#' the \code{dput} output and places it on the clipboard, as well as adding an assignment operator.
#'
#' @param object R object to convert to code
#' @param object R object to convert to code.
#' @param rows numeric. Vector of row numbers. These rows will be produced in the output.
#' By default, all rows are included.
#' @param indents integer. Spaces to be added before each line
#' @param indents integer. Spaces to be added before each line.
#' @param mdformat logical. Whether or not to add 4 spaces before every line in order to format as a code block.
#'
#' @author Tyler Rinker
#'
#' @examples
#' \dontrun{
#' SOdput(mtcars)
#' SOdput(mtcars, rows=1:6)
#' sodput(mtcars)
#' sodput(mtcars, rows=1:6)
#' }
#' @export

SOdput <- function(object, rows=TRUE, indents = 4, mdformat=TRUE) {
sodput <- function(object, rows=TRUE, indents = 4, mdformat=TRUE) {
name <- as.character(substitute(object))
name <- name[length(name)]

Expand Down
Loading