├── .Rbuildignore
├── .gitignore
├── DESCRIPTION
├── NAMESPACE
├── NEWS.md
├── R
├── addin.R
└── explode.R
├── README.Rmd
├── README.md
├── boom.Rproj
├── inst
└── rstudio
│ └── addins.dcf
└── man
├── boom.Rd
└── figures
└── logo.png
/.Rbuildignore:
--------------------------------------------------------------------------------
1 | ^boom\.Rproj$
2 | ^\.Rproj\.user$
3 | ^README\.Rmd$
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .Rproj.user
2 | .Rhistory
3 | .RData
4 |
--------------------------------------------------------------------------------
/DESCRIPTION:
--------------------------------------------------------------------------------
1 | Package: boom
2 | Title: Print the Output of Intermediate Steps of a Call
3 | Version: 0.0.0.9000
4 | Authors@R:
5 | person(given = "Antoine",
6 | family = "Fabri",
7 | role = c("aut", "cre"),
8 | email = "antoine.fabri@gmail.com")
9 | Description: 'explode' allows one to print the output of intermediate steps of a call, it is useful for debugging and teaching operation precedence.
10 | License: GPL-3
11 | Encoding: UTF-8
12 | Language: en
13 | LazyData: true
14 | Roxygen: list(markdown = TRUE)
15 | RoxygenNote: 7.1.1
16 | Imports:
17 | crayon
18 | Suggests:
19 | magrittr,
20 | lobstr
21 | URL: https://github.com/moodymudskipper/boom
22 | BugReports: https://github.com/moodymudskipper/boom/issues
23 |
--------------------------------------------------------------------------------
/NAMESPACE:
--------------------------------------------------------------------------------
1 | # Generated by roxygen2: do not edit by hand
2 |
3 | export(boom)
4 |
--------------------------------------------------------------------------------
/NEWS.md:
--------------------------------------------------------------------------------
1 | # boom 0.0.0.9000
2 |
3 | * Implemented an addin
4 |
--------------------------------------------------------------------------------
/R/addin.R:
--------------------------------------------------------------------------------
1 | boom_addin <- function() {
2 | # nocov start
3 |
4 | ## fetch context and selection
5 | context <- rstudioapi::getSourceEditorContext()
6 | selection <- rstudioapi::primary_selection(context)[["text"]]
7 | eval.parent(str2lang(paste0("boom::boom(",selection, ")")))
8 | invisible()
9 | # nocov end
10 | }
11 |
--------------------------------------------------------------------------------
/R/explode.R:
--------------------------------------------------------------------------------
1 |
2 | #' Print the Output of Intermediate Steps of a Call
3 | #'
4 | #' @param expr call to explode
5 | #'
6 | #' @export
7 | #'
8 | #' @examples
9 | #' boom(subset(head(mtcars, 2), qsec > 17))
10 | boom <- function(expr) {
11 | # if we are in a pipe chain, explode the chain above
12 | scs <- sys.calls()
13 | l <- length(scs)
14 | call_is_piped <-
15 | identical(scs[[l]][[2]], quote(.)) &&
16 | identical(scs[[l-1]][[1]], quote(`%>%`))
17 | if(call_is_piped) {
18 | call <- do.call(substitute, list(scs[[l]], list(. = scs[[l-1]][[2]])))
19 | eval.parent(call)
20 | }
21 | pf <- parent.frame()
22 | expr <- substitute(expr)
23 | funs <- setdiff(all.names(expr), c(all.vars(expr), "::", ":::"))
24 | wrapped <- list()
25 | for (fun in funs) {
26 | # fun will include namespaces, so we don't want to fail here if the object
27 | # doesn't exist
28 | if(!exists(fun, pf)) next
29 | fun_env <- environment(get(fun, envir = pf))
30 | # primitives don't have an environment, but they're in the base package
31 | if(is.null(fun_env)) {
32 | namespace <- "base"
33 | } else {
34 | namespace <- getNamespaceName(fun_env)
35 | }
36 |
37 | fun_val <- getExportedValue(namespace, fun)
38 | f <- as.function(c(alist(...=), bquote({
39 | sc <- sys.call()
40 | sc_bkp <- sc
41 | sc[[1]] <- .(fun_val)
42 | res <- eval.parent(sc)
43 | writeLines(crayon::cyan(deparse(sc_bkp)))
44 | print(res)
45 | })))
46 | environment(f) <- asNamespace(namespace)
47 | wrapped[[fun]] <- f
48 | }
49 | wrapped$`::` <- function(pkg, name) {
50 | pkg <- as.character(substitute(pkg))
51 | name <- as.character(substitute(name))
52 | fun <- getExportedValue(pkg, name)
53 | as.function(c(alist(...=), bquote({
54 | sc <- sys.call()
55 | sc_bkp <- sc
56 | sc[[1]] <- .(fun)
57 | res <- eval.parent(sc)
58 | writeLines(crayon::cyan(deparse(sc_bkp)))
59 | print(res)
60 | })))
61 | }
62 | wrapped$`:::` <- function(pkg, name) {
63 | pkg <- as.character(substitute(pkg))
64 | name <- as.character(substitute(name))
65 | fun <- get(name, envir = asNamespace(pkg), inherits = FALSE)
66 | as.function(c(alist(...=), bquote({
67 | sc <- sys.call()
68 | sc_bkp <- sc
69 | sc[[1]] <- .(fun)
70 | res <- eval.parent(sc)
71 | writeLines(crayon::cyan(deparse(sc_bkp)))
72 | print(res)
73 | })))
74 | }
75 | environment(wrapped$`::`) <- asNamespace("base")
76 | environment(wrapped$`:::`) <- asNamespace("base")
77 | invisible(eval(expr, envir = wrapped, enclos = parent.frame()))
78 | }
79 |
--------------------------------------------------------------------------------
/README.Rmd:
--------------------------------------------------------------------------------
1 | ---
2 | output: github_document
3 | ---
4 |
5 |
6 |
7 | ```{r, include = FALSE}
8 | knitr::opts_chunk$set(
9 | collapse = TRUE,
10 | comment = "#>",
11 | fig.path = "man/figures/README-",
12 | out.width = "100%"
13 | )
14 | ```
15 |
16 | # boom
17 |
18 | *{boom}* has been renamed to *{boomer}*, the name was conflicting with the CRAN
19 | package *{Boom}*. Sorry for the oversight, and enjoy
20 | [*{boomer}*](https://github.com/moodymudskipper/boomer)!
21 |
22 | *{boom}* won't be maintained and will be archived, possibly removed in the future.
23 |
24 | Thanks @Data_question for suggesting the new name first.
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | # boom
5 |
6 | *{boom}* has been renamed to *{boomer}*, the name was conflicting with
7 | the CRAN package *{Boom}*. Sorry for the oversight, and enjoy
8 | [*{boomer}*](https://github.com/moodymudskipper/boomer)\!
9 |
10 | *{boom}* won’t be maintained and will be archived, possibly removed in
11 | the future.
12 |
13 | Thanks @Data\_question for suggesting the new name first.
14 |
--------------------------------------------------------------------------------
/boom.Rproj:
--------------------------------------------------------------------------------
1 | Version: 1.0
2 |
3 | RestoreWorkspace: No
4 | SaveWorkspace: No
5 | AlwaysSaveHistory: Default
6 |
7 | EnableCodeIndexing: Yes
8 | UseSpacesForTab: Yes
9 | NumSpacesForTab: 2
10 | Encoding: UTF-8
11 |
12 | RnwWeave: Sweave
13 | LaTeX: pdfLaTeX
14 |
15 | AutoAppendNewline: Yes
16 | StripTrailingWhitespace: Yes
17 | LineEndingConversion: Posix
18 |
19 | BuildType: Package
20 | PackageUseDevtools: Yes
21 | PackageInstallArgs: --no-multiarch --with-keep.source
22 | PackageRoxygenize: rd,collate,namespace
23 |
--------------------------------------------------------------------------------
/inst/rstudio/addins.dcf:
--------------------------------------------------------------------------------
1 | Name: Explode a call
2 | Description: Print the Output of Intermediate Steps of a Call
3 | Binding: boom_addin
4 | Interactive: false
5 |
--------------------------------------------------------------------------------
/man/boom.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/explode.R
3 | \name{boom}
4 | \alias{boom}
5 | \title{Print the Output of Intermediate Steps Of a Call}
6 | \usage{
7 | boom(expr)
8 | }
9 | \arguments{
10 | \item{expr}{call to explode}
11 | }
12 | \description{
13 | Print the Output of Intermediate Steps Of a Call
14 | }
15 | \examples{
16 | boom(subset(head(mtcars, 2), qsec > 17))
17 | }
18 |
--------------------------------------------------------------------------------
/man/figures/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/moodymudskipper/boom/4b9309de9c1ac7557c3d8717cdd81cbc2df36b59/man/figures/logo.png
--------------------------------------------------------------------------------