Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stepping through a pipeline with intermediate results

Tags:

r

dplyr

magrittr

Is there a way to output the result of a pipeline at each step without doing it manually? (eg. without selecting and running only the selected chunks)

I often find myself running a pipeline line-by-line to remember what it was doing or when I am developing some analysis.

For example:

library(dplyr)

mtcars %>% 
  group_by(cyl) %>% 
  sample_frac(0.1) %>% 
  summarise(res = mean(mpg))
# Source: local data frame [3 x 2]
# 
# cyl  res
# 1   4 33.9
# 2   6 18.1
# 3   8 18.7

I'd to select and run:

mtcars %>% group_by(cyl)

and then...

mtcars %>% group_by(cyl) %>% sample_frac(0.1)

and so on...

But selecting and CMD/CTRL+ENTER in RStudio leaves a more efficient method to be desired.

Can this be done in code?

Is there a function which takes a pipeline and runs/digests it line by line showing output at each step in the console and you continue by pressing enter like in demos(...) or examples(...) of package guides

like image 781
andrew wong Avatar asked May 08 '15 08:05

andrew wong


People also ask

How many pipelined stages per instruction on unpipeline D machine?

©Speedup: Unpipelined/pipelined = # pipelined stages ©Thus pipelined time in general: 23 Number of pipe stage Time per instruction on unpipeline d machine Pipeline Performance (2/2) 24 Pipeline Hazards ©Hazards prevent the next instruction in the instruction steam from executing during its designated clock cycle

What is the performance of pipelining?

Pipelining Performance (1/2) ©Pipelining increases throughput, not reduce the execution time of an individual instruction. uIn face, slightly increases the execution time (an instruction) due to overhead in the control of the pipeline. uPractical depth of a pipeline is limited by increasing execution time.

What happens when an instruction is stalled in a pipeline?

For the than the stalled instruction—and hence not as far along in the pipeline—are also stalled. must cont inue, since otherwise the hazard will never clear. As a result, no new instructions are fetched during the stall. A stall causes the pipeline performance to degrade from the ideal performance.

Can U© happen in a 5-stage pipeline?

©Can’t happen in 5-stage pipeline because: uAll instructions take 5 stages, and uReads are always in stage 2, and uWrites are always in stage 5


1 Answers

You can select which results to print by using the tee-operator (%T>%) and print(). The tee-operator is used exclusively for side-effects like printing.

# i.e.
mtcars %>%
  group_by(cyl) %T>% print() %>%
  sample_frac(0.1) %T>% print() %>%
  summarise(res = mean(mpg))
like image 163
seasmith Avatar answered Sep 21 '22 06:09

seasmith