Search code examples
rdemo

How to create a demo for a presentation tutorial?


I want to prepare a demo (that will play sequentially in clicks) for a presentation tutorial...Can somebody help me how can I write a demo, suppose the following are steps in the demo...

#start 
set.seed(1345)
x1 <- sample(letters[1:10], 5)
x1 
sort(x1)
x <- sample(1:10, 5)  
 y <- sample(c(11:20), 5)
require(lattice) 
plot(x,y)
z <- rnorm(5, 1, 0.5)
dataframe <- data.frame(x, y, z)
model1 <- lm(y ~x)
aov(model1)
#end

Sorry I could find a solution after hours and days of search. I appreciate your help.


Solution

  • Another way to do it:

    1. Save your script in a file (demo.R)
    2. Edit the script and sprinkle it with pause() in strategic places
    3. In R, define pause <- function() invisible(readline())
    4. Run the script with source("demo.R", echo=TRUE)

    It will then print & run your commands and stop and wait for input at the sprinkled pause(). Just hit <Enter> to continue.

    EDIT: I don't know a good way to hide the pause() statement. A possible way would be to copy the code for source() and modify it to skip printing calls to pause(), but that's a little overkill I think...

    ...but you could rename the pause function to anything you like - including '....', but you still need to call it like this: ....()

    Hmmm. Maybe something like this:

    '....' <- function(...) invisible(readline())
    

    Then sprinkle your script with either:

    ....('Press Enter to continue')
    # Or
    ....(Press_Enter_to_continue)
    

    Another possibility if you rename the pause function to Pausing...:

    Pausing...(Press_Enter)