R plot shows uncommon hex like numbers on axis - r

I couldn't find an answer for this very easy question, because I don't know how to describe or even name the question. The code is extremly simple but it happens everytime I use the "plot" function in my jupyter notebook.
n <- 10
alpha <- rnorm(n,60,10)
beta <- rnorm(n,0,10)
Hbar <- 150
Hseq <- seq(from=130,to=170,len=30)
plot(NULL,xlim=c(130,170),ylim=c(10,100),xlab="height (cm)", ylab="weight (kg)")
for (i in 1:n)
lines(Hseq, alpha[i] + beta[i] * (Hseq-Hbar),
lwd=3, col=sample(1:10, 1))
The result looks like this:
For sure the axis should show "numeric numbers" instead of these "hex!?" onces. I think it have something to do with my R or jupyter version so:
Ubuntu LTS 20.4
anaconda 4.10.3
r-base 3.6.1
jupyter_client 7.1.0
jupyter_core 4.9.1
newest firefox version
Or maybe the keycode-table? What can I do?
Could this be helpful?
Sys.getlocale()
'LC_CTYPE=C.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C'
Update:
After restarting the conda enviroment and the r-kernel, it works without any changes in the code or packages. Even if I tried this before, I don't get it. So the cause or solution stays unclear.

Related

RStudio session aborts when I run gRbase::stepwise function (undirected graphs)

I'm doing an R project on RStudio (RStudio 2021.09.1+372 "Ghost Orchid" Release for Windows), (R version 4.1.2).
I'm working on Windows 10 x64.
I want to create an Undirected Graph from a dataset:
library(gRbase)
library(gRim)
library(gRain)
data(BodyFat)
BodyFat <- BodyFat[-c(31,42,48,76,86,96,159,169,175,182,206),]
BodyFat$Age <- sqrt(BodyFat$Age)
BodyFat$Weight <- sqrt(BodyFat$Weight)
names(BodyFat)[names(BodyFat) == 'BodyFat'] <- 'BodyFatPerc'
gRbodyfat <- BodyFat[,2:15]
graph.MyGraph <- cmod(~.^., data = gRbodyfat)
AIC.MyGraph <- gRbase::stepwise(graph.MyGraph)
I'm still exploring RStudio and graphical models, so I run these lines from the console, one by one.
When I run the last line of code, R session aborts and I get the following pop-up message:
I've also tried the following lines of code (I changed the last line):
library(gRbase)
library(gRim)
library(gRain)
data(BodyFat)
BodyFat <- BodyFat[-c(31,42,48,76,86,96,159,169,175,182,206),]
BodyFat$Age <- sqrt(BodyFat$Age)
BodyFat$Weight <- sqrt(BodyFat$Weight)
names(BodyFat)[names(BodyFat) == 'BodyFat'] <- 'BodyFatPerc'
gRbodyfat <- BodyFat[,2:15]
graph.MyGraph <- cmod(~.^., data = gRbodyfat)
AIC.MyGraph <- stepwise(graph.MyGraph)
but I get the same problem. I tried three or four times running those lines of code, R aborted everytime.
My gRbase, gRim, gRain, Rgraphviz and RBGL libraries are in the home folder:
C:/Users/MyUser/Documents/R/win-library/4.1
Any advice?
EDIT:
I've tried uninstalling/reinstalling R, Rtools, RStudio, reinstalling libraries, updating them, I've tried launching RStudio as Administrator, I've tried changing computer.
The last thing I tried is this:
uninstalling R, Rtools and RStudio
deleting .RData and .Renviron files in the Documents folder
deleting all libraries
downloading R (latest version) from CRAN webpage and installing it as Administrator
downloading Rtools (latest version from webpage) and installing it as Administrator
creating the .Renviron file as described here
downloading RStudio (latest version from webpage) and installing it as Administrator
installing BiocManager as described here (when asked to update Matrix library I said NO, I thought it could be the problem)
installing gRbase, gRim, gRain libraries as described here (when asked to update fansi library I said NO because it said "There are binary versions available but the source versions are later", I thought it could be the problem)
Tried again the lines of code
Still got the problem, R session aborted again.
A friend of mine doing a similar project used gRbase::stepwise function, so I inserted his code in the console and the function worked. So I think the problem might be the object of the function, graph.MyGraph. The cmod function works fine, so maybe there's a problem with gRbodyfat, which is used to build graph.MyGraph.
If I run these lines (I tried changing the dataset, I used BodyFat instead of gRbodyfat):
graph.MyGraph <- cmod(~.^., data = BodyFat)
AIC.MyGraph <- gRbase::stepwise(graph.MyGraph)
I get the following error:
Error in dim(res) <- c(NSEL, NSET) :
dims [product 210] do not match the length of object [14]
Don't know what to do.
EDIT:
I've tried debugging gRbase::stepwise function and I get this:
The problem appears to be the iModel function.
EDIT:
I've discovered that if I use graph.MyGraph <- cmod(~.^1, data = gRbodyfat) the gRbase::stepwise function works fine.

Setting up GUIs in R

Trying to create some GUIs in R.
I create a window and it disappears.
What am I missing here?
library(tcltk)
tt <- tktoplevel() <br>
x <- tkbutton(tt, text = "Text") <br>
tkpack(x)
What system do you use? It works just fine on macOS with R 3.4.1
This is strange. It should work fine from command line as well:
I assume that you have XQuartz (https://www.xquartz.org) installed and configured.

Why is locator() broken in RStudio?

Does anyone know how to fix when RStudio is breaking the locator() function? If I plot
plot(1:10)
then use locator() to click on the same points (1:10), this is what I get after I click the Finish button.
locator(type = 'p', col = 'red')
$x
[1] 1.265369 2.226131 3.172336 4.147655 5.064746 6.040065
[7] 6.986270 7.947032 8.893237 9.868556
$y
[1] 1.437224 2.361029 3.265178 4.169328 5.093133 5.997282
[7] 6.901432 7.825237 8.729386 9.633536
However, if I do the same thing in the R GUI rather than RStudio, then it works just fine:
I've tried restarting my session, using dev.off(), and restarting RStudio but the problem persists. Am I missing something simple here, or maybe it's a bug in RStudio?
R version 3.3.1
RStudio 0.99.903
Mac OSX 10.11.6

No graph output when using googleVIS in jupyter

Using this works in R console:
plot(G)
but when typed into a cell in jupyter I get:
starting httpd help server ... done
and no graph.
So here is what I did.
Into Anaconda 2.7.11, I installed R essentials
conda install -c r r-essentials
started up jupyter
notebook jupyter
installed needed reqs, XML and googleVIS, by typing this into a cell
options(repos=structure(c(CRAN="https://cloud.r-project.org/")))
install.packages('googleVis')
install.packages('XML')
typed this code into a cell
suppressPackageStartupMessages(library(googleVis))
library(googleVis)
library(XML)
url <- "http://en.wikipedia.org/wiki/List_of_countries_by_credit_rating"
x <- readHTMLTable(readLines(url), which=3)
levels(x$Rating) <- substring(levels(x$Rating), 4,
nchar(levels(x$Rating)))
x$Ranking <- x$Rating
levels(x$Ranking) <- nlevels(x$Rating):1
x$Ranking <- as.character(x$Ranking)
x$Rating <- paste(x$Country, x$Rating, sep=": ")
G <- gvisGeoChart(x, "Country", "Ranking", hovervar="Rating",
options=list(gvis.editor="S&P",
projection="kavrayskiy-vii",
colorAxis="{colors:['#91BFDB', '#FC8D59']}"))
then
plot(G)
This code works fine when typed directly into an R console and makes a nice map. But something is causing jupyter to choke on starting a server. I guess since jupyter itself is web page running in a server there is some sort of problem with a web page starting a server?
I have the same issue. According to this demonstration, all you need in an R console is to additionally add this line after loading the library:
library(googleVis)
op <- options(gvis.plot.tag='chart')
The introduction of tag can also be found here in googleVis's documentation. After trying it in Jupyter all I got is a block of .json data and it cannot compile into an interactive graph.
Hope this help in anyway. I will probably try something like plotly, which does work on jupyter.

RStudio-only error with tcl/tk?

When I compute an ROC plot with the package pROC, I get the following error in RStudio v. 99.9.9:
## Loading required package: tcltk
## Warning: couldn't connect to display ":0"
## Error: [tcl] invalid command name "toplevel".
I thought this was an issue in my OS (Debian with r-base 3.1 installed from APT depending on tcl/tk lib version 8.5), but when evaluating the same code through the terminal, I get the plot rendered without the same error.
Here is a simple example following some pROC example code that will generate the error when knitted in RStudio, but works in vanilla R:
```{r markdown.test}
library(pROC)
features <- runif(25)
labels <- as.factor(runif(25) < 0.75)
lda.model <- lda(as.matrix(features),labels)
lda.pred <- predict(lda.model,as.matrix(features))
lda.roc <- plot.roc(lda.pred$posterior[,1],
c(labels),
ci=TRUE, of="se", #specificities = seq(0,100,5),
ci.type="shape",
ci.col="#1c61b6AA")
```
The error occurs when the confidence interval parameters are added to the call.
Is there something missing from my RStudio install/config, or is this a bug?
Blast from the past! I see that same error today on an instance of RStudio installed in the IBM computing environment called CP4D. Did you ever find an answer?
I think the way to fix on your Macintosh is to install Quartz and let it serve as the X11 server to display output from programs like tcltk or maybe even hist() or quartz() devices. (my team wrote install instructions https://pj.freefaculty.org/guides/crmda_guides/47.mac_R_setup).
I'm not sure what I'll do on the CP4D thing, since it is running inside a Web browser.

Resources