在一个文档中定位到第一个空行,读取其后的所有文本,报错如下:

get.msg <- function(path)
{

con <- file(path, open = "rt", encoding = "latin1")

text <- readLines(con)

# The message always begins after the first full line break
msg <- text[seq(which(text == "")[1]+1, length(text), 1)]
close(con)
return(paste(msg, collapse = "\n"))
}
报错:
Error in seq.default(which(text == "")[1]+1, length(text), 1) : 
'from' cannot be NA, NaN or infinite
示例文档:
From 12a1mailbot1@web.de Thu Aug 22 13:17:22 2002
Return-Path: <12a1mailbot1@web.de>
Delivered-To: zzzz@localhost.spamassassin.taint.org
Received: from localhost (localhost [127.0.0.1])
by phobos.labs.spamassassin.taint.org (Postfix) with ESMTP id 136B943C32
for <zzzz@localhost>; Thu, 22 Aug 2002 08:17:21 -0400 (EDT)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Dwindows-1252" http-equiv=3DContent-T=
ype>

慕雪6442864
浏览 162回答 2
2回答

德玛西亚99

seq函数是产生序列用的他的用法是seq(from,to,by)或者是seq(下界,by=,length=)下面是用r运行的结果seq(2,6,2)[1] 2 4 6seq(10,by=2,length=5)[1] 10 12 14 16 18

qq_遁去的一_1

在一个文档中定位到第一个空行,读取其后的所有文本 &nbsp;get.msg <- function(path) &nbsp;{ &nbsp; &nbsp; &nbsp;con <- file(path, open = "rt", encoding = "latin1") &nbsp; &nbsp; &nbsp; &nbsp;text <- readLines(con) &nbsp; &nbsp; &nbsp;# The message always begins after the first full line break &nbsp; &nbsp;msg <-... 文档定位第空行读取其所文本get.msg <- function(path){con <- file(path, open = "rt", encoding = "latin1")text <- readLines(con)# The message always begins after the first full line breakmsg <- text[seq(which(text == "")[1]+1, length(text), 1)]close(con)return(paste(msg, collapse = "\n"))}报错:Error in seq.default(which(text == "")[1]+1, length(text), 1) :&nbsp;'from' cannot be NA, NaN or infinite 展开 示例文档:From 12a1mailbot1@web.de &nbsp;Thu Aug 22 13:17:22 2002Return-Path: <12a1mailbot1@web.de>Delivered-To: zzzz@localhost.spamassassin.taint.orgReceived: from localhost (localhost [127.0.0.1])by phobos.labs.spamassassin.taint.org (Postfix) with ESMTP id 136B943C32for <zzzz@localhost>; Thu, 22 Aug 2002 08:17:21 -0400 (EDT)<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><META content=3D"text/html; charset=3Dwindows-1252" http-equiv=3DContent-T=ype>
打开App,查看更多内容
随时随地看视频慕课网APP