Search code examples
rgwidgets

Open help page in R via gWidgets function


I want to give users of a gWidgets gui access to the R help pages. Below is a minimal example with two approaches that does not work. Both lines of codes work directly in the R command window (RGui in Windows). R version 3.1.0

Update: Implemented suggestion from jverzani (button 3). It works! Thanks! If you post it I can mark it as the accepted answer.

library(gWidgets)

gui <- function(){

  w <- gwindow(title="Access help pages", visible=TRUE)

  help1_btn <- gbutton(text="Help 1 (don't work)", container=w)

  addHandlerChanged(help1_btn, handler = function(h, ...) {

    # Open help page for function.
    with(globalenv(), help(matrix, package = base))
    print("PRESSED HELP 1!")


  } )

  help2_btn <- gbutton(text="Help 2 (don't work)", container=w)

  addHandlerChanged(help2_btn, handler = function(h, ...) {

    # Open help page for function.
    help(matrix, package = base)
    print("PRESSED HELP 2!")

  } )

  help3_btn <- gbutton(text="Help 3 (works!)", container=w)

  addHandlerChanged(help3_btn, handler = function(h, ...) {

    # Open help page for function.
    print(help("matrix", help_type="html"))
    print("PRESSED HELP 3!")

  } )

}

Solution

  • As jverzani suggested it works to print the output of help (see my updated question for a complete example):

    print(help("matrix", help_type="html"))