2017-08-30 22 views
0

我創建了一個腳本,用戶最初被要求輸入一些分配給變量的輸入。但是,當您啓動腳本時,R不會等待用戶輸入輸入來執行操作。在腳本啓動之前,我如何告訴R等待用戶的輸入?實際上,我的代碼如下所示:只需要R在開始執行動作之前等待用戶輸入

fun <- function(){ 
    x <<- readline("What is the value of x?") 
    y <<- readline("What is the value of y?") 
    z <<- readline("What is the value of z?") 
} 
fun() 

#BEGIN OF THE SCRIPT USING X, Y, Z 
+0

這段代碼在這裏工作。注意你不知道double ** << **;使用* <*代替R文檔中顯示的https://stat.ethz.ch/R-manual/R-devel/library/base/html/readline.html – tagoma

回答

1

以這種方式將輸入分配給變量。現在

fun <- function(){ 
    readline("What is the value of x?") ->> x 
    readline("What is the value of y?") ->> y 
    readline("What is the value of z?") ->> z 
    return (z) 
} 

,打電話給你的功能,但如果你想利用從鍵盤輸入的包裝在表達...

{ 
fun() 
library(httr) 
# this is a comment 
} 
+0

我試過了,但問題是一樣的:腳本繼續以腳本的代碼作爲用戶輸入:/ –

+0

你想從鍵盤上取三個數字值嗎? –

+0

我想讓用戶插入一個url,一個數字和一個文本:每個應該是一個由腳本處理的變量 –