找回密码
 注册
查看: 3080|回复: 2

File Open/Save dialogs in R tcltk 实例说明 有用处

[复制链接]
发表于 2013-6-3 15:43:29 | 显示全部楼层 |阅读模式
File Open/Save dialogs in R tcltkThe Open file dialogrequire(tcltk)fileName <- tclvalue(tkgetOpenFile()) # Very simple, isn't it?if (!nchar(fileName)) {    tkmessageBox(message = "No file was selected!")} else {    tkmessageBox(message = paste("The file selected was", fileName))}The code above produces the following window:



The Save file dialogrequire(tcltk)fileName <- tclvalue(tkgetSaveFile())if (!nchar(fileName)) {    tkmessageBox(message = "No file was selected!")} else {    tkmessageBox(message = paste("The file selected was", fileName))}The code above produces the following window:

Now we will assume that the user pressed Cancel:

Opening SPSS Files With The Open File DialogThis example was contributed by [url=mailtozric@web.de]Christian Schulz[/url]. It shows how to tell the OpenFile dialog what type of files to look for.
require(tcltk)getfile <- function() {    name <- tclvalue(tkgetOpenFile(        filetypes = "{{SPSS Files} {.sav}} {{All files} *}"))    if (name == "") return;    require(foreign)    # read.spss() is located in this package    SPSSdata <- read.spss(name, use.value.label = TRUE, to.data.frame = TRUE)    assign("myData", SPSSdata, envir = .GlobalEnv)}tt <- tktoplevel()button.widget <- tkbutton(tt, text = "Select SPSS File", command = getfile)tkpack(button.widget)# The content of the SPSS file is placed in the variable 'SPSSdata'
Pressing the button gives the following OpenFile dialog, which knows which file extension to look for. In this case, only files with the extension .sav are displayed. As I don't have SPSS installed on my computer, the .sav file listed below does not have an SPSS icon.

Saving (or opening) files with more than one possible extensionMultiple possibilities for file extensions (e.g. .jpg and .jpeg) can be separated by a space as follows:
jpegFileName <- tclvalue(tkgetSaveFile(initialfile = "foo.jpg",    filetypes = "{{JPEG Files} {.jpg .jpeg}} {{All files} *}"))

Created: James Wettenhall.
Last update: 20 Augustus 2005, by Philippe Grosjean.
Tested: R 2.1.1 under Windows XP sp2, with default Tcl/Tk installed with R.
回复

使用道具 举报

发表于 2013-6-4 09:45:53 | 显示全部楼层
good,thanks
回复 支持 反对

使用道具 举报

发表于 2013-9-12 22:03:28 | 显示全部楼层
文件控制的包? 这个有用啊,我先存着。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2024-11-22 06:06 , Processed in 0.021508 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表