Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
462 views
in Technique[技术] by (71.8m points)

Just started learning R, unable to render demo("graphics")

I googled around for this issue and couldn't find anything, but hopefully someone on SW can help diagnose this issue!

While running on R version 3.4.1, I tried running

demo("graphics")

and the result was a blank window, unable to render any of the colors/graph (see image).

After exiting out of the window and pressing return again, another blank window (exact same thing) pops up. When I exit out of the second window, I am left with the following command line output:

> demo("graphics")

demo(graphics)
    ---- ~~~~~~~~

Type  <Return>   to start : 

> #  Copyright (C) 1997-2009 The R Core Team
> 
> require(datasets)

> require(grDevices); require(graphics)

> ## Here is some code which illustrates some of the differences between
> ## R and S graphics capabilities.  Note that colors are generally 
specified
> ## by a character string name (taken from the X11 rgb.txt file) and 
that line
> ## textures are given similarly.  The parameter "bg" sets the background
> ## parameter for the plot and there is also an "fg" parameter which sets
> ## the foreground color.
> 
> 
> x <- stats::rnorm(50)

> opar <- par(bg = "white")

> plot(x, ann = FALSE, type = "n")
Hit <Return> to see next plot: 
Error in plot.new() : attempt to plot on null device

I checked, and the "graphics" package definitely exists and is in libPath. Moreover, it appears that demo("persp") also fails in a similar way. Anyone know what might be causing this issue?

Edit 1: Thanks for responding! I am running this from bash, on Ubuntu 16.04.

Here is the requested terminal output:

> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.3 LTS

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C              
 [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.4.1
> dev.off()
Error in dev.off() : cannot shut down device 1 (the null device)

Edit 2: Turns out, when I call

dev.new()

before a demo(), the demo is suddenly able to run. However, demo() will not run without it. This doesn't explain to me why demo() doesn't work off the start though.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...