【发布时间】:2017-02-02 16:20:57
【问题描述】:
我想要一个 readline() 函数来使用存储到变量中的字符串,而不是将用于变量的单词转换为字符串。有什么办法可以做到吗?
例如,假设我有以下变量和所需的提示:
> SpringC = c("Red", "Orange", "Yellow", "Green")
> WinterC = c("Blue", "White", "Purple", "Grey")
> x <- readline("Enter Season Color: ")
如果发生这种情况,我希望是:
Enter Season Color: WinterC
> x <- as.character(unlist(strsplit(x, ",")))
> x
"Blue" "White" "Purple" "Grey"
而不是实际发生的事情:
Enter Season Color: WinterC
> x <- as.character(unlist(strsplit(x, ",")))
> x
"WinterC"
【问题讨论】:
标签: r string variables command-prompt readline