- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否有任何 R 用户知道 R 中的“打开文件”类型函数?
最好有一个文本界面,例如:
> file.choose("/path/to/start/at")
path/to/start/at:
[1] [D] a_directory
[2] [D] another_directory
[3] [F] apicture.tif
[4] [F] atextfile.txt
...
[..] Go up a directory
Enter selection:
而且我可以浏览,直到我选择了我想要的文件。
file.choose
,但是(无论如何在 Linux 上)它只是说“输入文件名:”并接受您输入的任何内容,但不能让您浏览。 (也许在 Windows 上它会显示一个“打开文件”对话框?)。
multiple=F
通常人们希望选择一个文件。
#' Text-based interactive file selection.
#'@param root the root directory to explore
#' (default current working directory)
#'@param multiple boolean specifying whether to allow
#' multiple files to be selected
#'@return character vector of selected files.
#'@examples
#'fileList <- my.file.browse()
my.file.browse <- function (root=getwd(), multiple=F) {
# .. and list.files(root)
x <- c( dirname(normalizePath(root)), list.files(root,full.names=T) )
isdir <- file.info(x)$isdir
obj <- sort(isdir,index.return=T,decreasing=T)
isdir <- obj$x
x <- x[obj$ix]
lbls <- sprintf('%s%s',basename(x),ifelse(isdir,'/',''))
lbls[1] <- sprintf('../ (%s)', basename(x[1]))
files <- c()
sel = -1
while ( TRUE ) {
sel <- menu(lbls,title=sprintf('Select file(s) (0 to quit) in folder %s:',root))
if (sel == 0 )
break
if (isdir[sel]) {
# directory, browse further
files <- c(files, my.file.browse( x[sel], multiple ))
break
} else {
# file, add to list
files <- c(files,x[sel])
if ( !multiple )
break
# remove selected file from choices
lbls <- lbls[-sel]
x <- x[-sel]
isdir <- isdir[-sel]
}
}
return(files)
}
因为我使用
normalizePath
,所以它可能会因为符号链接(symbolic link)和“..”而出错。 , .. 但是哦,好吧。
最佳答案
我有一种你想要的东西,我保存在我的 .Rprofile 中。它有一个菜单界面,因为它默认用于查看工作目录。如果您希望将其扩展为从根目录开始并从那里使用菜单,则必须对功能进行大量修改。
该函数仅在菜单中查找 .txt .R 和 .Rnw 文件。
Open <- function(method = menu) {
wd<-getwd()
on.exit(setwd(wd))
x <- dir()
x2 <- subset(x, substring(x, nchar(x) - 1, nchar(x)) == ".R" |
substring(x, nchar(x) - 3, nchar(x)) %in%c(".txt", ".Rnw"))
if (is.numeric(method)) {
x4 <- x2[method]
x5 <- as.character(x4)
file.edit(x5)
} else {
switch(method,
menu = { x3 <- menu(x2)
x4 <- x2[x3]
x5 <- as.character(x4)
file.edit(x5)
},
look = file.edit(file.choose()))
}
}
##########
#Examples
#########
Open()
Open("L")
关于file - R命令行文件对话框?类似于 file.choose,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9122600/
我正在创建教师表格,我想从图库中选择图片作为个人资料,我想更改右侧“选择图片按钮”的标签和位置,以及左侧同一输入框中的“选择图片”标签和标签旁边“请选择个人资料图片”我正在使用 angular 和 b
我有一个 anchor a.add_input链接,负责向当前文档添加(通过jQuery)file输入字段。输入将附加到其他文件输入字段的列表中(OneToMany 关系上下文中的多个文件上传)。 最
Apple 的版本编辑器帮助只有两个主题,“将文件的版本与时间线进行比较”和“将文件的版本与跳转栏进行比较”,这两个主题都没有描述退出或向当前文件添加特定更改的方法文件的版本,或从正在比较的对创建 m
现在,当我选择要上传的图片时,提交表单效果很好。但是即使没有选择任何图像,我也尝试提交相同的表格... Controller function create(){ $this->dat
这个问题在这里已经有了答案: How does this CASE expression reach the ELSE clause? (3 个回答) 7年前关闭。 当我将随机整数生成与 CHOOSE
我希望我的下拉列表显示第一个值:“-选择汽车-” 我这样成功了: protected void ddl1_DataBound(object sender, EventArgs e) { Co
让我们以项目 A 及其依赖项(包括传递依赖项)为例。如果查看依赖关系树,我会看到在一条路径的末尾有 slf4j-api:1.6.4,在另一条路径的末尾有 slf4j:1.6.1。 我必须选择哪个依赖项
请考虑我的旧脚本: CHOOSE.EXE /c:ynq /t:n,7 " until 7 seconds press Y to smooth details " set "LowPassFilter=
MyBatis 中动态语句 choose-when-otherwise 类似于 Java 中的 switch-case-default 语句。由于 MyBatis 并没有为 if 提供对应的 else
我想使用相同的脚本来处理存储在不同位置的许多文本文件中的数据,然后将输出保存到另一个唯一的位置,而不必每次都修改我的脚本。我输入数据使用: data <- read.table(file.choose
作为作业的一部分,我正在使用 Scalacheck 来查找缺陷。令人难以置信的是,我被卡住了,因为它正在生成一对非零整数。 从我的 IntelliJ 工作表中,逐字逐句: import org.sca
我的数据如下所示: service,rating_1,rating_2,rating_3,rating_4,rating_5 renew_patent,0,0,1,2,11 apply_benefit
我在 Linux Mint 中安装了 mxnet。我使用 anaconda 来运行 python 3.5。我按照说明进行操作,成功安装了。 mxnet 和 anaconda 都是最新版本。但是,当我尝
有没有办法让file.choose()后弹出的对话窗口运行以显示自定义标题,类似于 X <- menu(files, graphics=TRUE, title="Choose file X") ? 现
我正在尝试使用 CHOOSE 函数从表中返回几个不相邻的列,based on this answer ,但结果看起来不正确。 模拟下表中的相同问题,发现结果是一样的。 可能会发生什么?这个公式与我的版
我必须承担一个项目,制作一个视频聊天应用程序。 该视频必须从一个位置进行流式传输,并且可供全局各地的多人观看。性能确实是一个问题,超过 2-3 秒的延迟是 Not Acceptable 。 据我所知,
您好,我的项目需要我使用 WebView 和相机。我在 HTML 中实现了代码,按下“选择文件”按钮后, WebView 将让我选择是使用相机捕获照片还是从文件管理器上传文件。但我不需要文件选项,我只
我想同时做接下来的事情: 在集合末尾添加新项目(经常) 从集合开始时删除项目(或少数项目)(经常) 从集合中间删除项目(或少数项目)(很少,通过迭代所有项目发生) 问题:哪个并发收集会给我最好的性能。
我使用 Bootstrap 框架创建了一个响应不同浏览器(台式机、平板电脑、移动设备)的在线网络应用程序。之后,我将网络应用程序转换为移动网络应用程序并在 Google Play 商店上发布,并在我的
经过大量阅读和实验后,似乎我需要 PRIMARY 搜索强度,但订购 TERTIARY 或 IDENTICAL。 主要问题:使用 H2(或任何其他数据库)可以实现吗? 次要问题:我是这里唯一的一个还是你
我是一名优秀的程序员,十分优秀!