gfile {gWidgets} | R Documentation

## 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"))
            ), multi=FALSE, 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

`text` | Initial text. For thecalendar, an optional date in a form matching `format`
`type` | When selecting a file it can be selected for opening, for saving or you may want to select a directory.
`initialfilename` | Suggested name for file save
`filter` | Filter for files shown during selection. Can be nested list, as in example or a named character vector with the names a description and value a file extension (no dots) of files endings to match.
`multi` | Logical. Allow selection of multiple files?
`quote` | Is result quoted
`format` | Format of date, default is year-month-day
`handler` | Handler for when file is changed. The component `file` of the first argument contains the file name
`action` | Passed to handler
`container` | Optional container to attach widget to
`...` | Passed to `gedit` instance
`toolkit` | Which GUI toolkit to use

### 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

    ## Not run:
    ## source a file using a handler
    sourceFile <- function() gfile("Select a file",type="open", handler =
    function(h,...) source(h$file))

    ## source an R file using fact that dialog is modal
    source(gfile(filter=c("R files"="R")))

    ## 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)))

    ## End(Not run)

[Package gWidgets version 0.0-54.2 Index]