我正在编写我的第一个 R 程序包,目前正在开发一个使用某些特定图形参数绘制绘图的函数。我希望在绘图完成后恢复用户定义的图形参数,但总是收到相同的警告消息:
opar <- par()
par(oma = c(5, 4, 0, 0) + 0.1, mar = c(0, 0, 1, 1) + 0.1)
par(opar)
Warning messages:
1: In par(opar) : graphical parameter "cin" cannot be set
2: In par(opar) : graphical parameter "cra" cannot be set
3: In par(opar) : graphical parameter "csi" cannot be set
4: In par(opar) : graphical parameter "cxy" cannot be set
5: In par(opar) : graphical parameter "din" cannot be set
6: In par(opar) : graphical parameter "page" cannot be set
有更好的方法吗?我知道 suppressWarnings()
函数,但 1. 我不希望消息被隐藏 和 2. 如果该函数被调用两次,则会出现一条警告消息:
> There were 12 warnings (use warnings() to see them)
最佳答案
您可以在保存图形参数时通过提供 no.readonly = TRUE
来绕过这些警告,如下所示:
opar <- par(no.readonly = TRUE)
par(oma = c(5, 4, 0, 0) + 0.1, mar = c(0, 0, 1, 1) + 0.1)
par(opar)
此外,您可以使用 dev.off()
恢复默认的 par
参数值。
希望对您有所帮助。
关于r - 恢复图形参数时的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53699637/