【发布时间】:2016-07-12 07:20:42
【问题描述】:
我想创建一个弹出的对话窗口,用户将能够选择多个 xlsx 文件并返回数据列表。我发现一个可能的解决方案是使用tk_choose.files,但它给了我一个错误。
choose.dir(getwd(), "Choose a suitable folder")
library(xlsx)
library(rJava)
library(xlsxjars)
library(tcltk)
#get file names
f = list.files("./")
#read files
dat = lapply(f, function(i){
x = tk_choose.files(caption="Choose your files"), read.xlsx(i, sheetIndex = 1, sheetName = NULL, startRow = 24,
endRow = NULL, as.data.frame = TRUE, header = FALSE)
#return columns with names and colors
x = x[, c(2, 5, 7, 9, 11, 13, 15, 17, 19), drop=FALSE]
#return the data
x
})
错误:意外的“,”在: “dat = lapply(f,函数(i){ x = tk_choose.files(caption="选择你的文件"),"
我知道语法有错误,但我对 R 很陌生,不知道如何正确编写。
有人可以帮忙吗?
【问题讨论】:
-
您要在
lapply中选择带有tk_choose.files的文件吗? -
对
library(rJava)和library(xlsxjars)的调用是多余的,因为library(xlsx)调用了所有依赖项 -
Uwe Block,是的,这就是我想要做的。不知道图书馆(xlsx),谢谢
-
如果您想避免未来的头痛,请使用
R赋值运算符<-而不是模棱两可的=(请参阅Chapter 8.2.26 "= is not a synonym of <-" of Patrick Burns' "The R Inferno")。 -
我尝试使用
<-而不是=,但我得到了同样的错误
标签: r xlsx lapply filechooser