2014-10-19 97 views
0

爲什麼read.clipboard()在我的系統上不起作用?爲什麼read.clipboard在R中不工作

> library(psych) 
> read.table(text=read.clipboard(), sep="\t", header=T, stringsAsFactors=F, strip.white=T) 
Error in textConnection(text, encoding = "UTF-8") : 
    invalid 'text' argument 
In addition: Warning message: 
In read.table(file("clipboard"), header = TRUE, ...) : 
    incomplete final line found by readTableHeader on 'clipboard' 


> read.table(text=readClipboard(), sep="\t", header=T, stringsAsFactors=F, strip.white=T) 
Error in textConnection(text, encoding = "UTF-8") : 
    could not find function "readClipboard" 

版本信息:

> packageVersion('psych') 
[1] ‘1.4.8.11’ 


> R.version 
       _       
platform  i486-pc-linux-gnu   
arch   i486       
os    linux-gnu     
system   i486, linux-gnu    
status          
major   3       
minor   1.1       
year   2014       
month   07       
day   10       
svn rev  66115      
language  R       
version.string R version 3.1.1 (2014-07-10) 
nickname  Sock it to Me    
> 

編輯:

至於建議的@RichardScriven,我使用了以下內容:

read.table('clipboard', sep="\t", header=T) 

如果我複製一些細胞,電子表格和嘗試上面的命令,它不起作用。以下是錯誤:

Error in file(file, "rt") : cannot open the connection 
In addition: Warning message: 
In file(file, "rt") : clipboard cannot be opened or contains no text 

但如果我先粘貼到文本編輯器,並從那裏再次複製,然後將上面的命令效果很好。

如何從電子表格複製後直接使用數據?

以下命令也顯示相同的問題,從文本編輯器複製時工作,但從電子表格複製時不起作用。我產生相同的錯誤。

> read.clipboard(sep="\t", header=T) 
Error in open.connection(file, "rt") : cannot open the connection 
In addition: Warning message: 
In open.connection(file, "rt") : 
    clipboard cannot be opened or contains no text 
+2

readClipboard只在Windows上可用。但是您可以嘗試'overflow :: readClip'來獲取非系統依賴的剪貼板閱讀器。看[這篇文章](http://stackoverflow.com/questions/24365249/readclipboard-removed-from-utils-package)。你也可以使用'read.table(「clipboard」,...)' – 2014-10-19 17:18:12

+0

你可能是對的,因爲它正在使用Windows R版本,我可以使用'wine'Linux軟件包在我的Linux系統上運行它。 – rnso 2014-10-19 17:21:59

+0

[此鏈接](http://www.cookbook-r.com/Data_input_and_output/Loading_and_storing_data_with_the_keyboard_and_clipboard/)也很有用 – 2014-10-19 17:23:30

回答

0

read.clipboard(SEP = 「\ t」 的,標題= T) 上述代碼應工作。另請注意,您需要複製[從excel/libreoffice等],轉到R腳本並在R中運行該命令。如果您執行其中任何其他命令,這可能無法正常工作。希望這可以幫助。