R语言画图-Error in get(getOption("device"))
2016-12-16 22:45
435 查看
环境为:
R 3.3.1, Rscript 3.3.1 64位
windows 7 64位
当运行如下示例程序画loglog图:
1 . 在RGui中的R Console中运行情况:
报错:
但是成功打开device并画图。
2 . 在
3 . 将示例代码存入脚本文件,在windows 7 x64
不输出结果文件。
Mac OS X 10.9.4中用
同样不输出结果文件。
解决方法:
针对
参照:
[1] http://r.789695.n4.nabble.com/R-2-8-0-get-platform-device-with-get-getOption-quot-device-quot-td920607.html
The “device” option can now be a function, and is one in some standard setups. Consequentially, get(getOption(“device”)) will fail; programmers should usually use dev.new() instead.
[2] https://stat.ethz.ch/pipermail/r-devel/2008-April/049319.html
2.7.0 provides a function dev.new()
.
As from R 2.5.0, options(“device”) can be a character string or a function. If the latter, this construct does not work.
[3] R in Action, Second Edition. Robert I. Kabacoff. May 2015. ISBN 9781617291388. 608 pages. printed in black & white.
First, you can open a new graph window before creating a new graph:
statements to create graph 1
statements to create a graph 2
etc.
Each new graph will appear in the most recently opened window.
R 3.3.1, Rscript 3.3.1 64位
windows 7 64位
当运行如下示例程序画loglog图:
## Create a data frame with artificial data. d.f <- data.frame( x = 1:100, y = 1:100 ) ## Open a new default device. get( getOption( "device" ) )() ## Plot the data, hiding the points for now to prevent the calls to ## abline() from drawing over the points. plot( y ~ x, data = d.f, type = "n", log = "xy", main = "Log-log Plot" ) ## Put grid lines on the plot, using a light blue color ("lightsteelblue2"). abline( h = seq( 0, 100, 10 ), lty = 3, col = colors()[ 440 ] ) abline( v = seq( 0, 100, 10 ), lty = 3, col = colors()[ 440 ] ) ## Draw the points over the grid lines. points( y ~ x, data = d.f ) ## Redraw the plot box over the grid lines. box()
1 . 在RGui中的R Console中运行情况:
报错:
Error in get(getOption("device")) : invalid first argument
但是成功打开device并画图。
> ## Create a data frame with artificial data. > > d.f <- data.frame( x = 1:100, y = 1:100 ) > > ## Open a new default device. > > get( getOption( "device" ) )() Error in get(getOption("device")) : invalid first argument > > ## Plot the data, hiding the points for now to prevent the calls to > ## abline() from drawing over the points. > > plot( y ~ x, data = d.f, type = "n", log = "xy", main = "Log-log Plot" ) > > ## Put grid lines on the plot, using a light blue color ("lightsteelblue2"). > > abline( h = seq( 0, 100, 10 ), lty = 3, col = colors()[ 440 ] ) > abline( v = seq( 0, 100, 10 ), lty = 3, col = colors()[ 440 ] ) > > ## Draw the points over the grid lines. > > points( y ~ x, data = d.f ) > > ## Redraw the plot box over the grid lines. > > box()
2 . 在
RStudio(Version 0.99.903)中,
get( getOption( "device" ) )()返回
NULL,并成功画图,单独运行该语句依然返回
NULL但是能成功打开device
> ## Create a data frame with artificial data. > > d.f <- data.frame( x = 1:100, y = 1:100 ) > > ## Open a new default device. > > get( getOption( "device" ) )() NULL > > ## Plot the data, hiding the points for now to prevent the calls to > ## abline() from drawing over the points. > > plot( y ~ x, data = d.f, type = "n", log = "xy", main = "Log-log Plot" ) > > ## Put grid lines on the plot, using a light blue color ("lightsteelblue2"). > > abline( h = seq( 0, 100, 10 ), lty = 3, col = colors()[ 440 ] ) > abline( v = seq( 0, 100, 10 ), lty = 3, col = colors()[ 440 ] ) > > ## Draw the points over the grid lines. > > points( y ~ x, data = d.f ) > > ## Redraw the plot box over the grid lines. > > box() > >
3 . 将示例代码存入脚本文件,在windows 7 x64
cmd中使用
Rscript运行脚本文件,报错:
Error in get(getOption("device")) :
不输出结果文件。
Mac OS X 10.9.4中用
Rscript运行脚本报错为:
Error in get(getOption("device")) : invalid first argument Execution halted
同样不输出结果文件。
解决方法:
针对
Rscript和
RConsole将
get(getOption("device"))改为
dev.new()
RConsole不再报错,
Rscript运行脚本正常默认输出pdf文件也不报错
参照:
[1] http://r.789695.n4.nabble.com/R-2-8-0-get-platform-device-with-get-getOption-quot-device-quot-td920607.html
The “device” option can now be a function, and is one in some standard setups. Consequentially, get(getOption(“device”)) will fail; programmers should usually use dev.new() instead.
[2] https://stat.ethz.ch/pipermail/r-devel/2008-April/049319.html
2.7.0 provides a function dev.new()
.
As from R 2.5.0, options(“device”) can be a character string or a function. If the latter, this construct does not work.
[3] R in Action, Second Edition. Robert I. Kabacoff. May 2015. ISBN 9781617291388. 608 pages. printed in black & white.
First, you can open a new graph window before creating a new graph:
dev.new()
statements to create graph 1
dev.new()
statements to create a graph 2
etc.
Each new graph will appear in the most recently opened window.
相关文章推荐
- 远程调试 ERROR: JDWP unable to get necessary JVMTI capabilities. ["debugInit.c",L279]
- 安装mytop 出现 Error in option spec: &quot;long|!&quot;
- Using Timer to get history values from EDNA database, an error is prompted in the page : "Sys.WebForms.PageRequestManagerTimeout
- 安装mytop 出现 Error in option spec: "long|!"
- R语言学习-问题解决-reached getOption("max.print")
- R语言 错误 Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod
- Exception in thread "main" java.lang.Error: Unresolved compilation problems 解决方案
- fprintf(stderr, "error para in %s(), in file %s, line %d/n", __FUNCTION__, __FILE__, __LINE__);
- eclipse更新时Error retrieving "feature.xml". [error in opening zip file]解决
- FIX: Error message when you try to install a large Windows Installer package or a large Windows Installer patch package in Windows Server 2003 or in Windows XP: "Error 1718. File was rejected by digital signature policy"
- Sharepoint Error : The URL "filename" is invalid. It may refer to a nonexistent file or folder, or refer to a valid file or folder that is not in the current Web
- (原創) 如何解決『Error: More than one programming cable found in available hardware list --use--list option to display available hardware list and specify correct cableprogramming』錯誤訊息? (SOC) (Nios II) (μClinux) (DE2) (DE2-70)
- PRB: "Requested Registry Access Is Not Allowed" Error Message When ASP.NET Application Tries to Write New EventSource in the Eve
- "An extender can't be in a different UpdatePanel than the control it extends." error really needs debugging information ,错误
- Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
- InputStream in = this.getClass().getResourceAsStream("photo.gif")的意思
- 安装oralce后在cmd模式下运行java命令出错:Exception in thread "main" java.lang.UnsupportedClassVersionError: org/getopt/luke/Luke (Unsupported
- Server Error in '/' Application. Access to the Path Is Denied" error message appears
- C2059 Error Using extern "C" in .C Source Files
- WinAPI: midiInGetErrorText - 根据错误号得到错误描述