Skip to content

Commit

Permalink
merged from main
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/branches/lazy@30251 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
ripley committed Jul 11, 2004
1 parent cf5bfcb commit 4c49c01
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion doc/html/R-admin.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 15 additions & 14 deletions src/library/utils/R/read.fwf.R
Expand Up @@ -15,20 +15,21 @@ function(file, widths, header = FALSE, sep = "\t", as.is = FALSE,

drop<- (widths<0)
widths<-abs(widths)


buffersize<-(buffersize %/% recordlength)* recordlength
FILENAME <- tempfile("Rfwf.")
on.exit(unlink(FILENAME))
FILE<-file(FILENAME,"a")

FILENAME <- tempfile("Rfwf.")
on.exit(unlink(FILENAME))
FILE<-file(FILENAME,"a")
on.exit(close(FILE),add=TRUE)

if (is.character(file))
file<-file(file,"r")
else if (!isOpen(file)) {
file<-open(file,"r")
on.exit(close(file))

if (is.character(file)) {
file <- file(file,"r")
on.exit(close(file),add=TRUE)
} else if (!isOpen(file)) {
file <- open(file,"r")
on.exit(close(file),add=TRUE)
}

if (skip)
Expand All @@ -37,13 +38,13 @@ function(file, widths, header = FALSE, sep = "\t", as.is = FALSE,
headerline<-readLines(file,n=1)
cat(FILE,headerline,"\n")
}

repeat({
if (n==-1)
thisblock<-buffersize
else
thisblock<-min(buffersize,n)

raw <- readLines(file, n=thisblock)
nread<-length(raw)
if (recordlength>1 && nread %% recordlength){
Expand All @@ -54,7 +55,7 @@ function(file, widths, header = FALSE, sep = "\t", as.is = FALSE,
raw<-matrix(raw,nrow=recordlength)
raw<-apply(raw,2,paste,collapse="")
}

st <- c(1, 1+cumsum(widths))
first <- st[-length(st)][!drop]
last <- cumsum(widths)[!drop]
Expand Down
5 changes: 3 additions & 2 deletions src/library/utils/man/read.fwf.Rd
Expand Up @@ -7,7 +7,8 @@
}
\usage{
read.fwf(file, widths, header = FALSE, sep = "\t", as.is = FALSE,
skip = 0, row.names, col.names, n = -1, buffersize=2000, \dots)
skip = 0, row.names, col.names, n = -1, buffersize = 2000,
\dots)
}
\arguments{
\item{file}{
Expand Down Expand Up @@ -45,7 +46,7 @@ read.fwf(file, widths, header = FALSE, sep = "\t", as.is = FALSE,
in \code{file} are replaced by \code{NA}.

Negative-width fields are used to indicate columns to be skipped, eg
code{-5} to skip 5 columns. These fields are not seen by
\code{-5} to skip 5 columns. These fields are not seen by
\code{read.table} and so should not be included in a \code{col.names}
or \code{colClasses} argument.

Expand Down

0 comments on commit 4c49c01

Please sign in to comment.