在gui(Windows gui或RStudio等)中时,我可以通过指定n=?从脚本中使用具有已知行数的readLines ,如下所示n=? 如果我不确定正在读取的行数(即,我有很多行并且不知道n)怎么办? 如何在gui中使用readLines (从外部文件中的脚本读取)而不指定n? 如果您不提供n,则显示readLines可以保持连接打开并保持在读取线上。 按下esc会停止该功能,但不会读取任何行。

x <- readLines(n=4)
** preparing package for lazy loading
** help
*** installing help indices
** building package indices

x

这是一个演示我要问的具体问题的视频

当张贴者以奇怪的格式(如下面的数据集)为您提供数据并且您想在不计入所有行的情况下读取数据时,此功能特别有用:

** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** preparing package for lazy loading
** help
*** installing help indices
** building package indices

编辑直到重新打开,Dason才能回答自己...

戴森建议使用ctrl + z,并且这样做有效(至少在Windows计算机上)

===============>>#1 票数:1

两种简单的解决方案。

  1. 将文本放入另一个文件,然后阅读。

  2. 不要使用readLines 引用文字:

x <- strsplit("** preparing package for lazy loading
** help
*** installing help indices
** building package indices
", "\n")


x
[[1]]
[1] "** preparing package for lazy loading" "** help"                               "*** installing help indices"          
[4] "** building package indices"          

===============>>#2 票数:1

您可以在文本textConnection引号,并创建textConnection以读取

text <- "** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** preparing package for lazy loading
** help
*** installing help indices
** building package indices"

readLines(textConnection(text))
# [1] "** preparing package for lazy loading" "** help"                              
# [3] "*** installing help indices"           "** building package indices"          
# [5] "** preparing package for lazy loading" "** help"                              
# [7] "*** installing help indices"           "** building package indices"          
# [9] "** preparing package for lazy loading" "** help"                              
#[11] "*** installing help indices"           "** building package indices"          
#[13] "** preparing package for lazy loading" "** help"                              
#[15] "*** installing help indices"           "** building package indices"          
#[17] "** preparing package for lazy loading" "** help"                              
#[19] "*** installing help indices"           "** building package indices"  

===============>>#3 票数:1

在Windows环境中,选择并复制到剪贴板后:

 (clip.input <- readLines( file("clipboard") ) )

在Mac / UNIX中:

 (clip.input <- readLines( pipe("pbpaste") ) )

  ask by Tyler Rinker translate from so

未解决问题?本站智能推荐: