简体   繁体   English

使用 Rscript 时如何在屏幕上保留 RGL 图?

[英]How to keep an RGL plot on the screen when using Rscript?

I have a very simple .r file:我有一个非常简单的 .r 文件:

library("rgl")
par(ask=TRUE)

x=c(0.44,0.45)
y=c(0.2, 0.3)
z=matrix(c(1,2,3,4),nrow=length(x))

persp3d(x,y,z)

When I open a cmd screen and navigate to my R installation and try当我打开一个 cmd 屏幕并导航到我的 R 安装并尝试

Rscript P:\pathtoscript\example.r

I see the persp3d graph flash up really quickly and then disappear, even though my .r file contains the par(ask=true) command.我看到persp3d图形非常快速地闪烁然后消失,即使我的persp3d文件包含par(ask=true)命令。

So my question is, how can I keep it up and play around with it, without it going away before I'm done?所以我的问题是,我怎样才能保持它并玩弄它,而不会在我完成之前消失?

Thanks for your help.谢谢你的帮助。

I'm not aware of a more idiomatic way to do this type of thing, but you can just add Sys.sleep(large_number_of_seconds) to keep the R process alive.我不知道做这种事情的更惯用的方法,但你可以添加Sys.sleep(large_number_of_seconds)来保持 R 进程的活动。 For example,例如,

script.R脚本文件

library("rgl")

x <- c(0.44, 0.45)
y <- c(0.2, 0.3)
z <- matrix(c(1,2,3,4),nrow = length(x))

persp3d(x,y,z)
Sys.sleep(100000)

Also, the ask argument to par is only used in interactive sessions, which is why it was not working here.此外, parask参数仅用于交互式会话,这就是它在这里不起作用的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM