Skip to content

Commit ec49b8d

Browse files
committed
fix R CMD check
1 parent 9c1f395 commit ec49b8d

File tree

4 files changed

+51
-11
lines changed

4 files changed

+51
-11
lines changed

R/qenv-get_outputs.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#' Get outputs
22
#'
3+
#' @description
34
#' `eval_code` evaluates code silently so plots and prints don't show up in the console or graphic devices.
4-
#' If one wants to use an output outside of the qenv (e.g. use a graph in `renderPlot`) then use `get_outputs`.
5+
#' If one wants to use an output outside of the `qenv` (e.g. use a graph in `renderPlot`) then use `get_outputs`.
56
#' @param object (`qenv`)
6-
#' @return list of outputs generated in a qenv
7+
#' @return list of outputs generated in a `qenv``
78
#' @examples
89
#' q <- eval_code(
910
#' qenv(),
@@ -14,10 +15,14 @@
1415
#' })
1516
#' )
1617
#' get_outputs(q)
18+
#'
19+
#' @aliases get_outputs,qenv-method
20+
#'
1721
#' @export
1822
setGeneric("get_outputs", function(object) standardGeneric("get_outputs"))
1923

2024

25+
2126
setMethod("get_outputs", signature = "qenv", function(object) {
2227
Reduce(
2328
function(x, y) {

_pkgdown.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ reference:
3131
- eval_code
3232
- get_code
3333
- get_env
34+
- get_outputs
3435
- get_var
3536
- get_messages
3637
- get_warnings

man/get_outputs.Rd

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-get_outputs.R

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
1-
testthat::test_that("", {
2-
q <- qenv()
3-
q1 <- eval_code(q, expression(iris, mtcars))
4-
testthat::expect_identical(
5-
get_outputs(q1),
6-
list(iris, mtcars)
7-
)
1+
testthat::describe("get_output", {
2+
testthat::it("returns an empty list if nothing is printed", {
3+
q <- qenv()
4+
q1 <- eval_code(q, expression(a <- 1L, b <- 2L))
5+
testthat::expect_identical(get_outputs(q1), list())
6+
})
7+
8+
testthat::it("implicitly printed objects are returned asis in a list", {
9+
q <- qenv()
10+
q1 <- eval_code(q, expression(a <- 1L, a, b <- 2L, b))
11+
testthat::expect_identical(get_outputs(q1), list(1L, 2L))
12+
})
13+
14+
testthat::it("explicitly printed objects are returned as console-output-string in a list", {
15+
q <- qenv()
16+
q1 <- eval_code(q, expression(a <- 1L, print(a), b <- 2L, print(b)))
17+
testthat::expect_identical(get_outputs(q1), list("[1] 1\n", "[1] 2\n"))
18+
})
19+
20+
testthat::it("printed plots are returned as recordedplot in a list", {
21+
q <- qenv()
22+
q1 <- eval_code(q, expression(a <- 1L, plot(a)))
23+
testthat::expect_true(inherits(get_outputs(q1)[[1]], "recordedplot"))
24+
})
25+
26+
testthat::it("warnings are returned asis in a list", {
27+
q <- qenv()
28+
q1 <- eval_code(q, expression(warning("test")))
29+
expected <- simpleWarning("test")
30+
expected["call"] <- NULL
31+
testthat::expect_identical(get_outputs(q1), list(expected))
32+
})
33+
34+
testthat::it("messages are returned asis in a list", {
35+
q <- qenv()
36+
q1 <- eval_code(q, expression(message("test")))
37+
expected <- simpleMessage("test\n", call = quote(message("test")))
38+
testthat::expect_identical(get_outputs(q1), list(expected))
39+
})
840
})

0 commit comments

Comments
 (0)