Learn R Programming

gWidgets (version 0.0-25)

gfile: Dialogs for file and date selection

Description

These functions provide dialogs for file selection (files or directories) and date selections.

Usage

gfile(text = "", type = c("open", "save", "selectdir"), initialfilename = NULL, 
    filter = list("All files" = list(patterns = c("*")), "R files" =
    list(patterns = c("*.R","*.Rdata")),
        "text files" = list(mime.types = c("text/plain"))
        ), handler = NULL, action = NULL, ..., toolkit = guiToolkit())

gfilebrowse (text = "Select a file...", type = "open", quote = TRUE, container = NULL, ..., toolkit = guiToolkit())

gcalendar(text = "", format = "%Y-%m-%d", handler=NULL, action=NULL, container = NULL, ..., toolkit = guiToolkit())

Arguments

Details

The gfile dialog is modal, meaning no action can take place until a selection is made. Whereas the gfilebrowse dialog consists of a gedit instance to hold a filename and a button to click if the dialog is desired to fill in this filename.

The gcalendar widget is similar to the gfilebrowse widget.

For both gcalendar and gfilebrowse any ... arguments are passed to gedit. The coerce.with argument can be used to here to quote the values, or coerce them otherwise such as with as.Date. Otherwise, the svalue method returns a character string containing the value shown in the gedit box.

The svalue<-() method may be used to set the value for both gcalendar and gfilebrowse .

The return value is the filename selected. A NA value is returned if no file is selected.

Examples

Run this code
## source a file using a handler
sourceFile = function() gfile("Select a file",type="open", handler =
function(h,...) source(h$file))

## source a file using fact that dialog is modal
source(gfile())

## apply a generic action to the file
countLines = function(filename) print(length(readLines(filename)))
chooseFile = function() gfile("Select a file",type="open",
action="countLines", handler = function(h,...) do.call(h$action,list(h$file)))

Run the code above in your browser using DataLab