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

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.

Related

Foreign(hebrew, Chinese) characters: Tidyverse incorrect display in console but correct in View() [duplicate]

For at least some cases, Asian characters are printable if they are contained in a matrix, or a vector, but not in a data.frame. Here is an example
q<-'天'
q # Works
# [1] "天"
matrix(q) # Works
# [,1]
# [1,] "天"
q2<-data.frame(q,stringsAsFactors=FALSE)
q2 # Does not work
# q
# 1 <U+5929>
q2[1,] # Works again.
# [1] "天"
Clearly, my device is capable of displaying the character, but when it is in a data.frame, it does not work.
Doing some digging, I found that the print.data.frame function runs format on each column. It turns out that if you run format.default directly, the same problem occurs:
format(q)
# "<U+5929>"
Digging into format.default, I find that it is calling the internal format, written in C.
Before I dig any further, I want to know if others can reproduce this behaviour. Is there some configuration of R that would allow me to display these characters within data.frames?
My sessionInfo(), if it helps:
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252
[3] LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
[5] LC_TIME=English_Canada.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] tools_3.0.1
I hate to answer my own question, but although the comments and answers helped, they weren't quite right. In Windows, it doesn't seem like you can set a generic 'UTF-8' locale. You can, however, set country-specific locales, which will work in this case:
Sys.setlocale("LC_CTYPE", locale="Chinese")
q2 # Works fine
# q
#1 天
But, it does make me wonder why exactly format seems to use the locale; I wonder if there is a way to have it ignore the locale in Windows. I also wonder if there is some generic UTF-8 locale that I don't know about on Windows.
I just blogged about Unicode and R several days ago. I think your R editor is UTF-8 and this gives your illusion that R in your Windows handles UTF-8 characters.
The short answer is when you want to process Unicode (Here, it is Chinese), don't use English Windows, use a Chinese version Windows or Linux which by default is UTF-8.
Session info in my Ubuntu:
> sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: i686-pc-linux-gnu (32-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C 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 LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

Function `Boot` from `R` package `car` can not find .carEnv

While using the Boot function from the car package I get the error message
Error in get(".y.boot", envir = .carEnv) : object '.carEnv' not found
I suspect I have inadvertently changed/set something in my OS and have no idea what it might be. Running the code below returns an error on my desktop but runs without error on a laptop running the same OS (Yosemite) as well as a desktop running Windows 7 (all using R-3.1.2). The code that triggers the message is
library(car)
swiss.lm <- lm(Fertility ~ Education, data = swiss)
BC <- Boot(swiss.lm, R = 999, method = "case") # No Problems
BR <- Boot(swiss.lm, R = 999, method = "residual") # Problems now
Error in get(".y.boot", envir = .carEnv) : object '.carEnv' not found
I have reinstalled R but the error still appears when running the above code. Any suggestions as to what I have done and how to get the code to run and find the environment would be most appreciated. TIA!
> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] car_2.0-24
loaded via a namespace (and not attached):
[1] boot_1.3-15 grid_3.1.2 lattice_0.20-29 lme4_1.1-7 MASS_7.3- 37 Matrix_1.1-5
[7] mgcv_1.8-4 minqa_1.2.4 nlme_3.1-119 nloptr_1.0.4 nnet_7.3-9 parallel_3.1.2
[13] pbkrtest_0.4-2 quantreg_5.11 Rcpp_0.11.4 SparseM_1.6 splines_3.1.2 tools_3.1.2
Looks like a reproducible bug in a car package. According to package news the changes in latest version (2.0-24) are related to .carEnv handling.
I tried to get around the issue by simply assigning the .carEnv before call to Boot with
.carEnv <- car:::.carEnv
This makes the Boot function execute without errors, but I am not sure of any other effects.
The package maintainer emailed me and indicated a bug had been introduced in 2.0-24 and that he would attempt to fix the bug.

LMERConvenienceFunctions error on back and forward fitting functions: model not a mer object

I tried using bfFixefLMER_t.fnc or fitLMER.fnc from the LMERConvenienceFunctions package. In both the cases, I get an error that "the input model is not a mer object".
I tried out the examples from http://artax.karlin.mff.cuni.cz/r-help/library/LMERConvenienceFunctions/html/00Index.html. I get the same errors.
For example when I run from the example
fitLMER.fnc(mB, backfit.on = "t", item = FALSE,
ran.effects = c("(FreqB | Subject)",
"(LengthB | Subject)", "(WMC | Item)"))
this is the result I get.
Warning in fitLMER.fnc(mB, backfit.on = "t", item = FALSE, ran.effects = c("(FreqB | Subject)", :resetting argument "method" to "t"
**backfitting fixed effects**
Warning in bfFixefLMER_t.fnc(model = model, item = item, method = method, :factor variable with more than two levels in model terms, backfitting on t-values is not appropriate, please use function "bfFixefLMER_F.fnc" instead.
Error in bfFixefLMER_t.fnc(model = model, item = item, method = method, : the input model is not a mer object
Has anyone had this experience with these functions?
There are functions that back fit fixed effects and forward fit random effects.
Is there a way to do forward fitting of fixed effects for the glmer models? Or is this statistically meaningless? I am working on ecological modelling, so my understanding of advanced stats is not much, so, please, if someone can explain in layman's terms better
sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_GB.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=C 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
other attached packages:
[1] LMERConvenienceFunctions_2.0 lme4_0.99999911-8
[3] RcppEigen_0.3.1.2.1 Rcpp_0.10.4
[5] Matrix_1.0-12 lattice_0.20-23
[7] LCFdata_1.0
loaded via a namespace (and not attached):
[1] grid_3.0.1 MASS_7.3-28 minqa_1.2.1 nlme_3.1-111 rpart_4.1-2
[6] splines_3.0.1 tools_3.0.1
You are using an (older) version of the overhauled lme4 package that returns merMod objects instead of mer objects, and hence is not compatible with LMERConvenienceFunctions. I get the same error when using the soon-to-be-released version 1.0-4.
If I install the latest version from CRAN instead (0.999999-2), no errors arise. I suggest removing your current lme4 and installing the latest from CRAN, and checking its version:
> detach("package:lme4",unload=TRUE)
> remove.packages("lme4")
> install.packages("lme4")
> packageVersion("lme4")
[1] ‘0.999999.2’
This should fix your problems. Be aware, however, that you will lose the advantages of the new version.
Also, in the coming days the new lme4 should appear on CRAN, breaking LMERConvenienceFunctions again if you update your packages. I guess, however, that the authors of LMERConvenienceFunctions will update their package soon to be compatible again.

R - XCMS package Error

I' ve the following problem :
Error in .C("NetCDFOpen", as.character(filename), ncid = integer(1), status = integer(1), :
C symbol name "NetCDFOpen" not in DLL for package "xcms"
How do you get this error :
nc <- xcms:::netCDFOpen(cdfFile)
ncData <- xcms:::netCDFRawData(nc)
xcms:::netCDFClose(nc)
I don't know why this don't works, although it should. For further info feel free to ask. Free .cdf files canf be found in the TargetSearchData package.
Code example :
## The directory with the NetCDF GC-MS files
cdfpath <- file.path(.find.package("TargetSearchData"), "gc-ms-data")
cdfpath
I don't think that it should, as you are implying. First, you are using a non-exported function through the :::. In addition, as stated by the error message, the is no NetCDFOpen symbol defined is the dll/so files.
Using the standard input functionality from xcms, works smoothly:
> library("xcms")
> cdfpath <- file.path(.find.package("TargetSearchData"), "gc-ms-data")
> cdfFile <- dir(cdfpath, full.names=TRUE)[1]
> xs <- xcmsSet(cdfFile)
7235eg04: 135:168 185:314 235:444 285:580
> xr <- xcmsRaw(cdfFile)
If you really want to input your data manually, you should use the functionality from the mzR package, which xcms depends on:
> openMSfile(cdfFile)
Mass Spectrometry file handle.
Filename: /home/lgatto/R/x86_64-unknown-linux-gnu-library/2.16/TargetSearchData/gc-ms-data/7235eg04.cdf
Number of scans: 4400
Finally, do pay attention to always provide the output of sessionInfo, to assure that you are using the latest version. In my case:
> sessionInfo()
R Under development (unstable) (2012-10-23 r61007)
Platform: x86_64-unknown-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8
[5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] BiocInstaller_1.9.4 xcms_1.35.1 mzR_1.5.1
[4] Rcpp_0.9.15
loaded via a namespace (and not attached):
[1] Biobase_2.19.0 BiocGenerics_0.5.1 codetools_0.2-8 parallel_2.16.0
[5] tools_2.16.0
although if might be different for you, if you use the stable version of R and Bioconductor (currently 2.15.2/2.11).
Hope this helps.

Help with x11 and dev.off

Why does this code throw warnings & how should I rewrite it?
x11(width = 8, height = 8)
plot(1:10)
points(1, 5, col='red')
dev.off() # Throws "Warning message: In dev.off() : Display list redraw incomplete"
The error disappears if I remove the x11() line. Thank you in advance,
Adrian
I can reproduce this bug, but only if I'm trying to source the code. I get two empty plot windows. You may have noticed that at first there's 8x8 X11 window, but then it's closed, and you end up with two default-sized windows (7x7), with the one in the front marked as ACTIVE. However, if you omit width and height parameters, everything works OK. This looks like X11 issue to me, and, frankly, I have no bloody idea what causes it, but it definitely has something to do with device geometry. If I set X11.options(width = 8, height = 8) and source the script, I get the same bug again.
Long story short, I can replicate the bug, but I have no idea what's causing it. Anyway, this yields no errors:
x11()
plot(1:10)
points(1, 5, col='red')
dev.off()
EDIT
I'm using Arch Linux FWIW, here's my sessionInfo():
R version 2.12.2 (2011-02-25)
Platform: i686-pc-linux-gnu (32-bit)
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=C 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

Resources