在Linux中运行R脚本时等待用户输入
发布时间:2020-05-23 09:58:19 所属栏目:Linux 来源:互联网
导读:我有一段代码提示用户输入,并在 Windows中运行代码时完美地工作.但是,在 Linux中,它执行每一行而不等待用户输入. 我已将代码添加到单独的函数中并使用系统(“stty -echo”)但未成功. 为什么会发生这种情况,可以做些什么? (执行命令:Rscript test.R) require
|
我有一段代码提示用户输入,并在 Windows中运行代码时完美地工作.但是,在 Linux中,它执行每一行而不等待用户输入. 我已将代码添加到单独的函数中并使用系统(“stty -echo”)但未成功. require(Biostrings)
read_value <- function(prompt_text = "",prompt_suffix = getOption("prompt"),coerce_to= "character")
{
prompt <- paste(prompt_text,prompt_suffix)
system("stty -echo")
as(readline(prompt),coerce_to)
}
prints<-function()
{ opt<-as.character(readline(prompt = "Enter parameter values: "))
system("stty -echo")
i<-1
while ((i<=5))
{ if (i==1)
{ expr.filename <- as.character(readline(prompt = "Expression file name: "))
tryCatch( {expr.file<-read.table(expr.filename)},error=function(e)
{print("ERROR : Enter valid filename!") return })
}
if (i==2)
{ system("stty -echo")
fasta.filename <- as.character(readline(prompt = "Fasta file name: "))
tryCatch( {sequence_data<-read.DNAStringSet(fasta.filename)},error=function(e)
{print("ERROR : Enter valid filename!") return })
}
#missing piece of code
i<-i+1
}
解决方法您可能需要考虑使用“stdin”中的readLines.提示功能用于记录数据集.cat("Please enter a file name ...")
fil <- readLines(con="stdin",1)
cat(fil,"n")
保存为filnam.r ….使用: user-linux-prompt$ Rscript filnam.r (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- backup – Rsync到AWS S3存储桶
- 在Linux上解析$PATH时我们必须考虑哪些极端情况?
- linux – 服务器锁定,/ var / log / messages报告“超出了积
- linux – ps aux用java进程挂在高cpu / IO上
- Linux:如何使用apt-get / aptitude恢复配置文件?
- ubuntu/linux 新增用户提示错误adduser: The group `xx alr
- FUSE挂载有可能破坏Linux服务器的稳定性?
- linux – 如何检索shell脚本中使用的所有工具
- c – 如何从unsigned char *模数和指数65537(RSA_F4)创建RS
- linux中的ssh端口转发(隧道)
推荐文章
站长推荐
热点阅读
