##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function(filename, column_types, column_widths,
column_names = paste("V", seq_len(length(column_types)), sep=""),
dec = ".") {
# check filename
if (!is.character(filename))
stop("filename should be of type character.")
filename <- as.character(filename[1])
if (!file_access(filename))
stop("Can not access file '", filename, "'.")
# check column_types
types <- laf_to_typecode(column_types)
# check column widths
if (!is.numeric(column_widths))
stop("column_widths should be of type numeric.")
if (length(column_widths) != length(column_types))
stop("Lengths of column_widths and column_types do not match.")
column_widths <- as.integer(column_widths)
# check column_names
if (!is.character(column_names))
stop("column_names should be of type character.")
if (length(column_names) != length(column_types))
stop("Lengths of column_names and column_types do not match.")
column_names <- make.names(column_names, unique=TRUE)
# check dec
if (!is.character(dec))
stop("dec should be of type character")
dec <- dec[1]
if (nchar(dec) != 1)
stop("The number of characters in dec is not equal to one.")
# open file
p <- .Call("laf_open_fwf", filename, types, column_widths, dec)
# create laf-object
result <- new(Class="laf",
file_id = as.integer(p),
filename = filename,
file_type = "fwf",
column_types = types,
column_names = column_names,
column_widths = column_widths
)
return(result)
}
Run the code above in your browser using DataLab