如何为演示教程创建演示?

发布于 2024-12-05 06:31:11 字数 383 浏览 1 评论 0原文

我想为演示文稿教程准备一个演示(将按顺序播放)...有人可以帮助我如何编写演示吗,假设以下是演示中的步骤...

#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

抱歉,我可以在之后找到解决方案搜索的时间和天数。我很感激你的帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

原来分手还会想你 2024-12-12 06:31:11

另一种方法:

  1. 将脚本保存在文件中 (demo.R)
  2. 编辑脚本并在重要位置添加 pause()
  3. 在 R 中,定义 pause <- function()无形(readline())
  4. 使用source("demo.R", echo=TRUE)运行脚本

然后它将打印&运行命令并停止并等待在 pause() 处输入。只需点击 即可继续。

编辑:我不知道隐藏 pause() 语句的好方法。一种可能的方法是复制 source() 的代码并修改它以跳过对 pause() 的打印调用,但我认为这有点矫枉过正

......。 ..但是您可以将暂停函数重命名为您喜欢的任何名称 - 包括 '....',但您仍然需要像这样调用它: ....()

嗯。也许是这样的:

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

然后在您的脚本中添加以下任一内容:

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

如果将暂停函数重命名为 Pausing...,还有另一种可能性:

Pausing...(Press_Enter)

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)
伊面 2024-12-12 06:31:11

执行您想要的操作的一种巧妙方法是:

  • 将命令另存为脚本,例如 testDemo.r
  • 复制到现有包的演示文件夹中,例如 /base/demo
  • 使用 demo(testDemo,package="base") 运行,

但它会在页面中暂停,而不是通过命令暂停。但最终,您可能想要创建自己的包来包含自定义演示。

编辑

看来demo的代码主要是为了检查演示是否存在,其核心非常简单:

op <- options(device.ask.default=TRUE)
source("testDemo.r",echo=TRUE,max.deparse.length=Inf,keep.source=TRUE)
options(op)

请注意,任何暂停都是由图形的存在来完成的,不是任何长度的回显文本,就像 demo 的实际情况一样。

A hacky way of doing what you want is:

  • Save commands as a script, eg testDemo.r
  • Copy into and existing package's demo folder, eg <Library>/base/demo
  • Run with demo(testDemo,package="base")

But it pauses in pages rather than by command. Ultimately though, you may want to create your own package to contain custom demos.

Edit

It seems the code for demo is mainly for checking that a demo exists, and the core is quite simple:

op <- options(device.ask.default=TRUE)
source("testDemo.r",echo=TRUE,max.deparse.length=Inf,keep.source=TRUE)
options(op)

Note that any pausing is only done by the presence of graphics, not any length of echoed text, as is actually the case with demo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文