@@ -447,7 +447,8 @@ eval.msgs <- function(src, env = NULL, showInvisible = FALSE, graph.unify = eval
447
447
# ' 'ggplot(mtcars) + geom_point(aes(x = hp, y = mpg))')
448
448
# ' evals(txt)
449
449
# '
450
- # ' ## the same commands in one string but also evaluating the `plot` with `text` (note the leading "+" on the beginning of `text...` line)
450
+ # ' ## the same commands in one string but also evaluating the `plot` with `text`
451
+ # ' ## (note the leading "+" on the beginning of `text...` line)
451
452
# ' txt <- 'df <- mtcars
452
453
# ' plot(mtcars$hp, pch = 19)
453
454
# ' +text(mtcars$hp, label = rownames(mtcars), pos = 4)
@@ -462,51 +463,58 @@ eval.msgs <- function(src, env = NULL, showInvisible = FALSE, graph.unify = eval
462
463
# '
463
464
# ' ## adding a caption to a plot
464
465
# ' evals('set.caption("FOO"); plot(1:10)')
465
- # ' ## `plot` is started with a `+` to eval the codes in the same chunk (no extra chunk with NULL result)
466
+ # ' ## `plot` is started with a `+` to eval the codes in the same chunk
467
+ # ' ## (no extra chunk with NULL result)
466
468
# ' evals('set.caption("FOO"); +plot(1:10)')
467
469
# '
468
470
# ' ## handling warnings
469
471
# ' evals('chisq.test(mtcars$gear, mtcars$hp)')
470
- # ' evals(list(c('chisq.test(mtcars$gear, mtcars$am)', 'pi', 'chisq.test(mtcars$gear, mtcars$hp)')), parse = F)
471
- # ' evals(c('chisq.test(mtcars$gear, mtcars$am)', 'pi', 'chisq.test(mtcars$gear, mtcars$hp)'))
472
+ # ' evals(list(c('chisq.test(mtcars$gear, mtcars$am)', 'pi',
473
+ # ' 'chisq.test(mtcars$gear, mtcars$hp)')), parse = FALSE)
474
+ # ' evals(c('chisq.test(mtcars$gear, mtcars$am)',
475
+ # ' 'pi',
476
+ # ' 'chisq.test(mtcars$gear, mtcars$hp)'))
472
477
# '
473
478
# ' ## handling errors
474
479
# ' evals('runiff(20)')
475
480
# ' evals('Old MacDonald had a farm\\dots')
476
481
# ' evals('## Some comment')
477
482
# ' evals(c('runiff(20)', 'Old MacDonald had a farm?'))
478
- # ' evals(list(c('runiff(20)', 'Old MacDonald had a farm?')), parse = F )
483
+ # ' evals(list(c('runiff(20)', 'Old MacDonald had a farm?')), parse = FALSE )
479
484
# ' evals(c('mean(1:10)', 'no.R.function()'))
480
- # ' evals(list(c('mean(1:10)', 'no.R.function()')), parse = F )
485
+ # ' evals(list(c('mean(1:10)', 'no.R.function()')), parse = FALSE )
481
486
# ' evals(c('no.R.object', 'no.R.function()', 'very.mixed.up(stuff)'))
482
- # ' evals(list(c('no.R.object', 'no.R.function()', 'very.mixed.up(stuff)')), parse = F )
487
+ # ' evals(list(c('no.R.object', 'no.R.function()', 'very.mixed.up(stuff)')), parse = FALSE )
483
488
# ' evals(c('no.R.object', 'Old MacDonald had a farm\\dots', 'pi'))
484
- # ' evals('no.R.object;Old MacDonald had a farm\\dots;pi', parse = F )
485
- # ' evals(list(c('no.R.object', 'Old MacDonald had a farm\\dots', 'pi')), parse = F )
489
+ # ' evals('no.R.object;Old MacDonald had a farm\\dots;pi', parse = FALSE )
490
+ # ' evals(list(c('no.R.object', 'Old MacDonald had a farm\\dots', 'pi')), parse = FALSE )
486
491
# '
487
492
# ' ## graph options
488
493
# ' evals('plot(1:10)')
489
494
# ' evals('plot(1:10);plot(2:20)')
490
495
# ' evals('plot(1:10)', graph.output = 'jpg')
491
496
# ' evals('plot(1:10)', height = 800)
492
- # ' evals('plot(1:10)', height = 800, hi.res = T )
493
- # ' evals('plot(1:10)', graph.output = 'pdf', hi.res = T )
497
+ # ' evals('plot(1:10)', height = 800, hi.res = TRUE )
498
+ # ' evals('plot(1:10)', graph.output = 'pdf', hi.res = TRUE )
494
499
# ' evals('plot(1:10)', res = 30)
495
500
# ' evals('plot(1:10)', graph.name = 'myplot')
496
501
# ' evals(list('plot(1:10)', 'plot(2:20)'), graph.name = 'myplots-%d')
497
502
# ' evals('plot(1:10)', graph.env = TRUE)
498
503
# ' evals('x <- runif(100);plot(x)', graph.env = TRUE)
499
504
# ' evals(c('plot(1:10)', 'plot(2:20)'), graph.env = TRUE)
500
505
# ' evals(c('x <- runif(100)', 'plot(x)','y <- runif(100)', 'plot(y)'), graph.env = TRUE)
501
- # ' evals(list(c('x <- runif(100)', 'plot(x)'), c('y <- runif(100)', 'plot(y)')), graph.env = TRUE, parse = F)
506
+ # ' evals(list(
507
+ # ' c('x <- runif(100)', 'plot(x)'),
508
+ # ' c('y <- runif(100)', 'plot(y)')),
509
+ # ' graph.env = TRUE, parse = FALSE)
502
510
# ' evals('plot(1:10)', graph.recordplot = TRUE)
503
511
# ' ## unprinted lattice plot
504
512
# ' evals('histogram(mtcars$hp)', graph.recordplot = TRUE)
505
513
# '
506
514
# ' ## caching
507
515
# ' system.time(evals('plot(mtcars)'))
508
- # ' system.time(evals('plot(mtcars)')) # running again to see the speed-up :)
509
- # ' system.time(evals('plot(mtcars)', cache = FALSE)) # cache disabled
516
+ # ' system.time(evals('plot(mtcars)')) # running again to see the speed-up :)
517
+ # ' system.time(evals('plot(mtcars)', cache = FALSE)) # cache disabled
510
518
# '
511
519
# ' ## caching mechanism does check what's inside a variable:
512
520
# ' x <- mtcars
@@ -517,12 +525,13 @@ eval.msgs <- function(src, env = NULL, showInvisible = FALSE, graph.unify = eval
517
525
# ' system.time(evals('plot(x)'))
518
526
# '
519
527
# ' ## stress your CPU - only once!
520
- # ' evals('x <- sapply(rep(mtcars$hp, 1e3), mean)') # run it again!
528
+ # ' evals('x <- sapply(rep(mtcars$hp, 1e3), mean)') # run it again!
521
529
# '
522
530
# ' ## play with cache
523
531
# ' require(lattice)
524
532
# ' evals('histogram(rep(mtcars$hp, 1e5))')
525
- # ' ## nor run the below call - which would return the cached version of the above call :)
533
+ # ' ## nor run the below call
534
+ # ' ## that would return the cached version of the above call :)
526
535
# ' f <- histogram
527
536
# ' g <- rep
528
537
# ' A <- mtcars$hp
@@ -552,9 +561,11 @@ eval.msgs <- function(src, env = NULL, showInvisible = FALSE, graph.unify = eval
552
561
# ' evals('matrix(runif(25), 5, 5)', hooks = list('matrix' = round))
553
562
# '
554
563
# ' ## setting default hook
555
- # ' evals(c('runif(10)', 'matrix(runif(9), 3, 3)'), hooks = list('default'=round))
564
+ # ' evals(c('runif(10)', 'matrix(runif(9), 3, 3)'),
565
+ # ' hooks = list('default'=round))
556
566
# ' ## round all values except for matrices
557
- # ' evals(c('runif(10)', 'matrix(runif(9), 3, 3)'), hooks = list(matrix = 'print', 'default' = round))
567
+ # ' evals(c('runif(10)', 'matrix(runif(9), 3, 3)'),
568
+ # ' hooks = list(matrix = 'print', 'default' = round))
558
569
# '
559
570
# ' # advanced hooks
560
571
# ' hooks <- list('numeric' = list(round, 2), 'matrix' = list(round, 1))
@@ -572,11 +583,14 @@ eval.msgs <- function(src, env = NULL, showInvisible = FALSE, graph.unify = eval
572
583
# ' # note the following will not be filtered!
573
584
# ' evals('matrix(1,1,1)', length = 1)
574
585
# '
575
- # ' # if you do not want to let such things be eval-ed in the middle of a string use it with other filters :)
586
+ # ' # if you do not want to let such things be eval-ed in the middle of a string
587
+ # ' # use it with other filters :)
576
588
# ' evals('matrix(1,1,1)', length = 1, classes = 'numeric')
577
589
# '
578
- # '# hooks & filtering
579
- # ' evals('matrix(5,5,5)', hooks = list('matrix' = pander.return), output = 'result')
590
+ # ' # hooks & filtering
591
+ # ' evals('matrix(5,5,5)',
592
+ # ' hooks = list('matrix' = pander.return),
593
+ # ' output = 'result')
580
594
# '
581
595
# ' # eval-ing chunks in given environment
582
596
# ' myenv <- new.env()
0 commit comments