How to get rid of side effect of tcltk2 package? - r

After working with the tcltk2 library to create a GUI window in R, when I revert to using a window produced with a package which depends on tcltk (without the 2), I get this error message on Windows 7:
Error in col2rgb(col) : invalid color name 'SystemButtonFace'
It must be that tcltk2 changes some underlying options for working with GUIs in R, because the error message is absent prior to loading tcltk2. I am working with the following version of R:
R version 3.1.0 (2014-04-10) -- "Spring Dance"
Is there a way to deal with this side effect (i.e., remove it)?
I tried to simply detach the tcltk2 package (which is a supplement to the tcltk package), but that doesn't do it.
I also tried replacing the colours in the GUI window that generated the error messages with R colour names like "red" and "blue" (instead of colours like #CCCFFF).
Any help would be greatly appreciated.
Thanks,
Isabella

It is not just an annoyance - it prevents R from properly displaying subsequent GUI windows.
I've put together some example R code. The code uses the PBSmodelling package to create an R GUI window (where the package depends on tcltk but not on tcltk2, both of which are R packages). The GUI window thus created is properly displayed in R. However, after loading the tcltk2 package in R and trying to display the same window again, I get the error message:
Error in col2rgb(col) : invalid color name 'SystemButtonFace'
To give you some context, most of the R GUI windows I've written for my project so far rely on PBSmodelling and work fine. I only need to use tcltk2 to create a couple of windows for the project, but these windows cannot (at least at the moment) be integrated with the majority of the other windows because of the above mentioned error message.
Here is the R code that will reproduce the error message:
## install & require PBSmodelling package
## for creating R GUI windows
install.packages("PBSmodelling")
require(PBSmodelling)
## function to plot a sinusoid (to be called by GUI window)
myPlot <- function() {
getWinVal(scope="L");
x <- seq(0,500)*2*n*pi/500;
plot(x,sin(x),type="l");
}
## create an R GUI window with PBSmodelling
winStr=c( "window title=Simple",
"entry name=n value=5",
"button function=myPlot text=\"Plot sinusoid\"")
## display R GUI window created with PBSmodelling
createWin(winStr,astext=TRUE)
## install & require tcltk2 package
install.packages("tcltk2")
require(tcltk2)
## try to display R GUI window created with PBSmodelling,
## this time after loading the tcltk2 package in R
createWin(winStr,astext=TRUE)
## Error message:
## Error in col2rgb(col) : invalid color name 'SystemButtonFace'
If you have any ideas for resolving this issue, please let me know.
Many thanks,
Isabella

Related

Cannot not find "calc.RL.0" function within "mixstock" package

I am trying to run through a mixed stock analysis in RStudio based on the walkthrough provided by Bolker (https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=043730a02b148396ebd54b2f62e8f6364714b1b2), using the 'mixstock' package and the example 'lahanas98raw' dataset within. However, I am receiving a warning that the 'calc.RL.0' function cannot be found whilst trying to carry out Raftery and Lewis convergence diagnostics (p.14 of Bolker's walkthrough). I am wondering whether one of the packages has not installed properly (i.e., either 'mixstock' or 'coda'), or whether there is another package I can use to run this diagnostic instead.
When I initially tried to install the 'mixstock' package, the following warning came up:
'Warning in install.packages : package ‘mixstock’ is not available for this version of R.'
I tried installing the version of R (2.14.1) described as the 'current version of R' on page 2 of Bolker's walkthrough, but when I then tried to switch to this version of R in RStudio via the options menu, it says that this version of R is not compatible with RStudio. To work around this, I downloaded the 'mixstock' package (version 0.9.5.1) from the CRAN archive (https://cran.r-project.org/src/contrib/Archive/mixstock/) and uploaded it to RStudio this way instead.
This seemed to have worked, as I successfully ran through a significant amount of the code, but a new error arose when I tried to run Raftery and Lewis convergence diagnostics (p.14). When I try to run calc.RL.0(mydata), I receive the following error:
'Error in calc.RL.0(mydata) : could not find function "calc.RL.0"'
However, when I click on 'mixstock' in the package window, everything seems fine and the 'calc.RL.0' function appears, alongside several other 'calc' functions (e.g. 'calc.GR', 'calc.mult.GR', 'calc.mult.RL') that can all be found and run fine. The 'calc.RL.0' function relies on the 'raftery.diag' function within the 'coda' package, so I have also made sure that is installed and called. I have tried a bunch of other methods but nothing seems to be working.
Here is some of my code leading up to the warning message:
## Calculate confidence intervals - i.e., bootstrapping - and plot them
mydata.umlboot = genboot(mydata,"uml")
confint(mydata.umlboot)
plot(mydata.umlboot, ylim=c(0,1))
## Carry out Markov Chain Monte Carlo (MCMC) estimations and plot them
mydata.mcmc = tmcmc(mydata)
mydata.mcmc
confint(mydata.mcmc)
plot(mydata.mcmc, ylim=c(0,1))
## Check that the Markov chains have converged = run Raftery and Lewis diagnostics
library(mixstock)
library(coda)
calc.RL.0(mydata)
'Error in calc.RL.0(mydata) : could not find function "calc.RL.0"'
Could this be something to do with the way the 'mixstock' package was initially installed, or is it likely to be another issue? Is there another way to run Raftery and Lewis diagnostics and still get the outputs I need (diagnostics for the last chain evaluated; the history of how long each suggested chain was)? Any help would be much appreciated - thanks in advance!
The most reliable way to install mixstock, if you have development tools installed on your computer (compilers etc.), is remotes::install_github("bbolker/mixstock") (I don't think I've changed anything/fixed any bugs since the archived version, but if I did the changes would be reflected on GitHub.)
It looks like I forgot to export that function, so
mixstock:::calc.RL.0(mydata)
should work (this is something I can/should fix). Note that the Gelman-Rubin diagnostic (calc.GR(), which is properly exported) is more reliable than Raftery-Lewis anyway ...

MessageBox in R

I would like to create a messagebox using R. A short research suggested the tcltk package. The tcltk::tk_messageBox() command actually worked the first time I tried it.
However, I then I updated to Windows 10, switched to R 3.4.3, using RStudio v1.1.423. Now the same command does not work, actually terminating the R Session. A second research showed that this is indeed an issue other users have experienced as well.
So, here is my question: Is there either a way to resolve the compatibility issue of the tcltk library and R/RStudio? Alternatively, is there another package that could produce the same result? (I would like to avoid going as far as shiny, that has been suggested)
With Windows 7, R 3.4.3 and RStudio 1.1.423 I have a similar problem, it looks like RStudio hangs, but in fact, the message-box has popped up, just that it does not become the active window and I have to minimize RStudio to see it.
The command I am running is:
tcltk::tk_messageBox(caption = "Hi", message = "what?", icon = "info", type = "yesno")

prevent rgl from opening window in package examples

I have several packages that make extensive use of rgl in documentation examples. Every time I do R CMD check, every such example opens a collection of rgl windows briefly, which is annoying.
Is there some rgl setting I can use in the .Rd files to suppress this behavior? Is there any downside to doing this?
Set the environment variable RGL_USE_NULL=TRUE and rgl won't try to open any windows.
This should be done outside of R, before running R CMD check. It can also be done inside R using Sys.setenv(RGL_USE_NULL = TRUE) before loading rgl if you don't want to see rgl displays during an interactive session.

Setting log levels in RdotNet

I am trying to use the R {forecast} package on Windows using RDotNet.
Question: Is there a way to control the level of logging output across RDotNet/R?
For example, executing the RdotNet code
var accuracy = rengine.Evaluate("accuracy(fcst)").AsNumeric();
causes the result of evaluation to get logged to console (or log file) as well.
Is there a way to control this either in RDotNet or R or {forecast} ?
(I had tried this sometime ago using R 3.1.1 and RdotNet 1.5.15. Recently I upgraded to the latest - R 3.2.2 and RdotNet 1.6.5. I don't recall seeing this in the previous versions.)
The REngine object has a property AutoPrint, set to true by default (mirroring the default behavior of R). Setting it to false will not print things out unless explicitly requested via the print function (I think, as I recall).
You can look at this sample code to see it used. Also, a recent discussion touched on this.

R View() function does not show data frame

I am using R (Version 3.1.2) with RStudio (Version 0.98.1091) on a Linux Ubuntu machine. I have a csv file loaded in variable:
rr <- read.csv("/home/user/seconds.csv")
When I call View(rr) I expect to open a new tab and display the CSV data in the rr variable. However, it opens a new tab called rr and it displays the following message.
/content?title=rr&file=94af460bd6644d3aaac734d585046c4f.htm not found
The View function is from package 'utils' which is not supported by the version of R you are using.
I am on a x86_64-w64-mingw32 system with R version 3.4.1, but I want to share a simple solution to get View working again in my case.
Following the step 4 of advice from Tian on Rstudio support (https://support.rstudio.com/hc/en-us/community/posts/115007743908-The-Rstudio-view-not-work-just-blank-), I entered:
install.packages("dplyr", dependencies = TRUE)
Now it works.

Resources