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

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)

Related

Fatal Error in R when using tcltk::tkentry

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.

read_pptx() throwing error when trying to read a pptx template file

I am trying to generate a report using a template .pptx file provided to me (originally within a zipped folder, which I extracted and saved locally).
R is giving me the following error when I run this code:
doc <- read_pptx('template_files/empty_template/RL_Template.pptx')
Error in tmp_names[match(old_, tmp_names)] <- new_ :
NAs are not allowed in subscripted assignments
The file RL_Template.pptx is a powerpoint template that will be populated with text and images. All scripts, data files, and templates are contained inside an R project, again, saved locally.
I have tried to execute the same line of code on a different machine of mine and get the same error, although a collaborator can successfully download/unzip the same files, run the same code, and generate the appropriate powerpoint output. He and I are running the same versions of R and RStudio.
I can successfully run this line of code to create a new object in R:
foo<-read_pptx()
and can add content to foo using add_slide()
I have updated all associated packages. I have full admin privileges on my machine so it should not be an error with read/write permissions.
It seems like maybe a problem with zip? Any ideas would be appreciated.
Session info:
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
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] dplyr_0.8.4 readxl_1.3.1 flextable_0.5.7 officer_0.3.6 SWMPrExtension_1.1.2 SWMPr_2.3.1
[7] zoo_1.8-7 ggplot2_3.2.1

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.

Unable to use svDialogs without attaching to search path

I need to obtain user input from the svDialogs R package, e.g. using svDialogs::dlgInput(). However, attempting to do this without attaching the package with library() or require() gives an error:
svDialogs::dlgInput("Example")
Error in svDialogs::dlgInput("Example") : attempt to apply non-function
The following works fine:
library(svDialogs)
svDialogs::dlgInput("Example")
Why might this be, and what might be a way around it? I have the current CRAN version of the package (0.9.57).
Update
I have tried installing previous versions of svDialogs, as well as comparing my code with the source code from the cgam package, which depends on svDialogs. Currently the entire svDialogs package is imported in my NAMESPACE, which is how it is used in cgam. But I still get the same error unless I first run library(svDialogs). Any tips?
Update 2
I also imported the entire svGUI package in my NAMESPACE, with no luck.
sessionInfo() R version 3.4.3 (2017-11-30)
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
[3] 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
other attached packages: [1] svDialogs_0.9-57 svGUI_0.9-55
loaded via a namespace (and not attached): [1] compiler_3.4.3
tools_3.4.3

Warning whenever I run sourceCpp

I am having trouble running Rcpp on my PC in RStudio. Whenever I sourceCpp() a cpp file, even the Hello World file that comes with Rcpp::Rcpp.package.skeleton(), I get the warning
In normalizePath(path.expand(path), winslash, mustWork) :
path[1]=".../anRpackage/src/../inst/include": The system cannot find the path specified
I searched Stackoverflow and it looks like some people get this warning if they don't have Depends: Rcpp in the DESCRIPTION of their package, but I am just running sourceCpp() so the DESCRIPTION file shouldn't matter (I also changed my DESCRIPTION file).
It is just a warning so the class and functions I wrote do appear in R, but RStudio frequently crashes after I use the functions in R a few times, which may or may not be related.
My session info:
R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)
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] Rcpp_0.12.1 RevoUtilsMath_7.4.1 RevoUtils_7.4.1 RevoMods_7.4.1 RevoScaleR_7.4.1 lattice_0.20-30 rpart_4.1-9
loaded via a namespace (and not attached):
[1] codetools_0.2-10 foreach_1.4.2 grid_3.1.3 iterators_1.0.7 tools_3.1.3
I suppose it is possible that Revolution R is the culprit here, but I have no way of knowing. I would appreciate help, because I don't want to ignore this warning, and it's obviously not ideal for RStudio to crash repeatedly.
Kind Regards
This is still relevant today, so here's my discoveries.
Rcpp can generate interfaces to and from C++ and R.
These are generated with the help of attributes specified in source-files.
From these attributes, the call to Rcpp::compileAttributes() produces the headers. Whilst at it, this also create the folder <package directory>/inst/include. If you have specified no attributes, anywhere, then compileAttributes() does not create these directories.
In order to get rid of this warning, create the <package directory>/inst/include.
For more on attributes, see Rcpp attributes vignette.

Resources