[英]R rename dataset
I'm creating a GUI using Tcltk package and I would like to know if there is a way to rename the dataset I'm importing. 我正在使用Tcltk软件包创建GUI,我想知道是否可以重命名要导入的数据集。 Basically, I would like the user to choose a name for the dataset he imports, but my code below is not giving me that.
基本上,我希望用户为他导入的数据集选择一个名称,但是下面的代码没有给我这样的名称。 What Im trying to do is the same concept as RStudio does when importing a file.
我试图做的是与RStudio导入文件时相同的概念。 Can someone point me to the right direction?
有人可以指出我正确的方向吗?
Thank you in advance! 先感谢您!
require(tcltk)
tt <- tktoplevel()
tkwm.title(tt, "Read Text Data")
dsName <- tclVar("Dataset")
entry.Name <-tkentry(tt,width="20",textvariable=dsName)
entry.box <- tklabel(tt,text="Please enter dataset name:")
tkgrid(entry.box, entry.Name)
tkgrid(tklabel(tt,text=""))
onOk <- function()
{
myval <- tclvalue(tkgetOpenFile())
myData <<- read.table(myval, header=TRUE, sep=",", dec = ".")
}
OK.but <- tkbutton(tt,text=" Import ",command=onOk)
Qt.but <- tkbutton(tt,text=" Cancel ",command=function()tkdestroy(tt))
tkgrid(OK.but, Qt.but)
tkfocus(tt)
Instead of this line: 代替此行:
myData <<- read.table(myval, header=TRUE, sep=",", dec = ".")
Try something like: 尝试类似:
myData <- read.table(myval, header=TRUE, sep=",", dec = ".")
assign(tclvalue(dsName), myData, envir = .GlobalEnv)
Though you may want to make envir = .GlobalEnv
something else (if you're planning to put this on CRAN, you can't assign to the global environment in this way and instead have to use a user-created environment). 尽管您可能希望将
envir = .GlobalEnv
其他名称(如果打算将其放置在CRAN上,则不能以这种方式分配给全局环境,而必须使用用户创建的环境)。
Some other notes: 其他注意事项:
tkdestroy
call at the end of your onOK
function. onOK
函数的末尾进行tkdestroy
调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.