Fatal Error in R when using tcltk::tkentry - r

I recently upgraded my R to 4.0.1 from 3.4.1 because I needed to use the TSP package and hadn't updated R in a while. TSP only requires greater than 3.5.0 but I figured I would install the latest version, right?
Now, I'm trying to run code I use daily for the past several years but am getting a fatal error in both R Studio and the R console. It uses the tcltk library to store username and password, which is crucial as I pull in SQL data from our server to utilize in my code. I don't want to store my credentials in the code, and it's a hassle as our passwords change monthly.
I've tried looking at other questions, such as Fatal Error After Upgrading R / R Studio but that doesn't seem to be the problem.
Here's my sessionInfo():
R version 4.0.1 (2020-06-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.0.1 tools_4.0.1
I suspect that tcltk::tkentry is the issue, as I went line by line and that's what causes the fatal error.
Here's my function:
getLoginDetails <- function(){
## Based on code by Barry Rowlingson
## http://r.789695.n4.nabble.com/tkentry-that-exits-after-RETURN-tt854721.html#none
require(tcltk)
tt <- tktoplevel()
tkwm.title(tt, "Get login details")
Name <- tclVar("Login ID")
Password <- tclVar("Password")
entry.Name <- tkentry(tt,width="20", textvariable=Name)
entry.Password <- tkentry(tt, width="20", show="*",
textvariable=Password)
tkgrid(tklabel(tt, text="Please enter your login details."))
tkgrid(entry.Name)
tkgrid(entry.Password)
OnOK <- function()
{
tkdestroy(tt)
}
OK.but <-tkbutton(tt,text=" OK ", command=OnOK)
tkbind(entry.Password, "<Return>", OnOK)
tkgrid(OK.but)
tkfocus(tt)
tkwait.window(tt)
invisible(c(loginID=tclvalue(Name), password=tclvalue(Password)))
}
credentials <- getLoginDetails()
The package loads correctly and capabilities("tcltk") comes back as TRUE.
The empty tktoplevel() will load:
But then this error message pops up and R Studio aborts:
Any help would be appreciated! I need this getLoginDetails function for my daily work activities.
If someone has an alternative, I would be open to that, too.
Cheers!

The problem appears to be with TclTk. Rcmdr won't run in R-4.0.1 but runs OK in R-4.0.0
My home-brew package won't load if Tcltk functionality is called.

The release notes for R 4.0.2 report that the bug has been fixed in that version:
Using tcltk widgets no longer crashes R on Windows.

Related

Package-specific utils::news() not working in RStudio

I'm trying to bring up news for a package while in RStudio. While the default utils::news() works for generating the base R changelog in the built-in viewer, I can't get it to work for a specific package; it throws an error. The function works fine for specific packages in RGui.
Fresh R session in RStudio 1.2.1335:
news() # this works
news(package = "ggplot2") # this doesn't
Error that I get in viewer: Error in UseMethod("toHTML") : no applicable method for 'toHTML' applied to an object of class "NULL"
Fresh R session in RGui:
news()
news(package = "ggplot2") # both work perfectly
Session info:
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.6.0 tools_3.6.0 Rcpp_1.0.1 xml2_1.2.0 commonmark_1.7
How can I get the function to output without error in RStudio? If this is not possible, how can I run the function in RStudio but tell it to view the HTML outside of the viewer, e.g., in the browser like RGui?
This looks like an RStudio bug, so probably the best action is to report it to them. As a workaround, you can avoid using their built-in browser by changing the setting for options("browser").
For example, on a Mac outside of RStudio I see
options("browser")
# $browser
# [1] "/usr/bin/open"
and in RStudio running
options(browser = "/usr/bin/open")
disables the built-in browser. I don't know what it defaults to in RGui on Windows, but setting it to the same in RStudio as it is in RGui should get it to work.
Unfortunately, this disables it for everything, not just for news(), so you probably want something like this instead:
save <- options(browser = "/usr/bin/open")
news(package = "ggplot2")
options(save)

Unable to install Github packages in R

I need a packages witch is located on Github. And I am aware that there are multiple solutions to install the package in R.
I am trying to install the package on a Windows server. This is what I tried:
Solution 1 (which is based on the Vignette)
install.packages("devtools")
library("devtools")
devtools::install_github("bmschmidt/wordVectors")
Error: Could not find tools necessary to compile a package
In addition: Warning messages:
1: In strptime(xx, f, tz = tz): unable to identify current timezone 'C':
Please set environment variable 'TZ'
I tried many things to solve this:
Reinstalling Devtools, use the CRAN devtools version
Reinstalling R and Rstudio (installing the latest versions as admin) (Error : Could not find build tools necessary to build)
But still the same error...
So I tried a workaround to install the packages on my computer:
Solution two
Download ZIP file from (https://github.com/bmschmidt/wordVectors)
Unzip the ZIP file
But the result is an error again:
library(devtools)
install("path/to/unzipped/file")
library("wordVectors")
Error there is no packages called wordVectors.
Anyone an idea what is going on? I struggled the whole day with this issue. Help is really appreciated! Thanks!
Edit
Also Rtools is (re)installed (the latest version...)
Edit 2
As requested in the comments (#DJV):
> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server >= 2012 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets
[6] methods base
loaded via a namespace (and not attached):
[1] compiler_3.5.2 tools_3.5.2

package ‘rJava’ is in use and will not be installed

I have been using R for a while without problems. Just a sudden, i have several issues with Rjava errors. I searched online for clues, but found none.
The error is: Warning in install.packages :
package ‘rJava’ is in use and will not be installed
and now every time i run install.packages, i get a pop box that says uploading loaded packages.....
sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] miniUI_0.1.1.1 tabulizer_0.2.2 rJava_0.9-10
Every time i start RStudio, i get this error:
Loading required package: rJava
Error: package or namespace load failed for ‘rJava’ in exists(what, mode = "function", envir = ns):
reached elapsed time limit
I made sure that i had java versions for 64 bit and the environment was set correctly.
install.packages("rJava");library(rJava)
I want to have a solution so that rjava loads correctly when i start RStudio or install rjava
This looks like you are loading tabulizer on startup, which also loads rJava. I suspect the reason is that you have a file called .RDATA saved in your default working environment. That makes RStudio open and load it on starting. In that file, I suspect there is an object which needs tabulizer. This is why it is loaded on default and why you have these problems.
The solution is to delete or rename the .RDATA file. Use getwd() to find out your current working directory. You might need to make hidden files visible.

Error: "package 'genomatic' does not have a namespace and should be reinstalled

I have just enough experience with R to get some things done, but not enough to actually troubleshoot a problem like this. I also would not call myself a programmer, though at some point that would be great. In case it matters, I usually use Rstudio.
I am trying to solve a problem where I have different entries for the same sample (microsatellites with different runs) that I need to condense into one line of information for each sample. I found the perfect package to solve my problem (package = genomatic). The trouble is, that I could not install it for use with the most recent version of R because it was created before version 3.0. So I downloaded version 2.15.3 and am working with the regular bare bones console.
Genomatic was not available through the install packages list, so I downloaded a zip file for Windows from here: http://www2.uaem.mx/r-mirror/web/packages/genomatic/index.html
and then followed the directions from pages 6-7 in the manual (link below) to install it from my own machine.
http://people.oregonstate.edu/~knausb/software/Genomatic_users_manual_v05.pdf
It appeared to install just fine, however when I go to load the library, I get the following error:
> library(genomatic)
Loading required package: tcltk
Loading Tcl/Tk interface ... done
Error in library(genomatic) :
package ‘genomatic’ does not have a NAMESPACE and should be re-installed
I looked through the forum, but could not find an answer for how to fix this. Here is the session info:
> sessionInfo()
R version 2.15.3 (2013-03-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] tcltk stats graphics grDevices utils datasets methods
[8] base
Can somebody help me to make this work?
Thanks!
Liz
EDIT to add: I did try to reinstall, but ended up with the same results.
I'm not sure why you're getting this particular error, as the .zip file provided does appear to have a NAMESPACE file. Installing from source (which shouldn't require any extra installed tools, since the package has only R code, not any compiled [C++/C/FORTRAN] components) seems to help. You can either do this from the official CRAN archives:
library("devtools")
install_version("genomatic",version="0.0.7")
or from the old/frozen repository:
install.packages("genomatic",
repos="http://www2.uaem.mx/r-mirror/", type="source")
(My previous answer was wrong; there is a NAMESPACE file.)

Updating R in Windows

Following this post and also this link , I tried to update my R version .
sessionInfo()
R version 2.14.0 (2011-10-31)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] installr_0.9
loaded via a namespace (and not attached):
[1] tools_2.14.0
But when I ran the code
updateR()
Error in file(con, "r") : cannot open the connection
It shows exactly the same error while running the following command :
check.for.updates.R() # tells you if there is a new version of R or not.
Error in file(con, "r") : cannot open the connection
install.R() # download and run the latest R installer
Error in file(con, "r") : cannot open the connection
How can I update my R version ?
Per https://github.com/talgalili/installr/#troubleshooting,
Try running:
setInternet2(TRUE)
That worked for me when I was getting the below error message:
Error in file(con, "r") : cannot open the connection
The URLs of the installr package are probably out of date. Just go the R website and download the latest version.
You will have to reinstall your packages manually though, which can be a pain. You can use rownames(installed.packages()) in your old R to get a list of the packages you currently have installed so that when you go to your new R you can just work down the list and install them all again.
You could even do
sprintf('install.packages(%s)', paste(shQuote(rownames(installed.packages())),collapse=','))
and then copy-paste that command into your new R to try reinstall everything you had installed on your old R. I personally prefer though to just install them as I need them, so that if I had packages I no longer use in the old R, I don't bother to reinstall them on the new R unless I need them.
Also, the above may fail simply because your current R is quite old compared to the new R so some packages may no longer be compatible.

Resources