foreign: Read Data Stored by Minitab, S, SAS, SPSS, Stata, Systat, Weka, dBase, ...

> library(foreign)

バージョン: 0.8.66


関数名 概略
data.restore Read an S3 Binary or data.dump File
lookup.xport Lookup Information on a SAS XPORT Format Library
read.arff Read Data from ARFF Files
read.dbf Read a DBF File
read.dta Read Stata Binary Files
read.epiinfo Read Epi Info Data Files
read.mtp Read a Minitab Portable Worksheet
read.octave Read Octave Text Data Files
read.spss Read an SPSS Data File
read.ssd Obtain a Data Frame from a SAS Permanent Dataset, via read.xport
read.systat Obtain a Data Frame from a Systat File
read.xport Read a SAS XPORT Format Library
write.arff Write Data into ARFF Files
write.dbf Write a DBF File
write.dta Write Files in Stata Binary Format
write.foreign Write Text Files and Code to Read Them

read.arff

read.dta

> read.dta
function (file, convert.dates = TRUE, convert.factors = TRUE, 
    missing.type = FALSE, convert.underscore = FALSE, warn.missing.labels = TRUE) 
{
    if (length(grep("^(http|ftp|https)://", file))) {
        tmp <- tempfile()
        download.file(file, tmp, quiet = TRUE, mode = "wb")
        file <- tmp
        on.exit(unlink(file))
    }
    rval <- .External(do_readStata, file)
    if (convert.underscore) 
        names(rval) <- gsub("_", ".", names(rval))
    types <- attr(rval, "types")
    stata.na <- data.frame(type = 251L:255L, min = c(101, 32741, 
        2147483621, 2^127, 2^1023), inc = c(1, 1, 1, 2^115, 2^1011))
    if (!missing.type) {
        if (abs(attr(rval, "version")) >= 8L) {
            for (v in which(types > 250L)) {
                this.type <- types[v] - 250L
                rval[[v]][rval[[v]] >= stata.na$min[this.type]] <- NA
            }
        }
    }
    else {
        if (abs(attr(rval, "version")) >= 8L) {
            missings <- vector("list", length(rval))
            names(missings) <- names(rval)
            for (v in which(types > 250L)) {
                this.type <- types[v] - 250L
                nas <- is.na(rval[[v]]) | rval[[v]] >= stata.na$min[this.type]
                natype <- (rval[[v]][nas] - stata.na$min[this.type])/stata.na$inc[this.type]
                natype[is.na(natype)] <- 0L
                missings[[v]] <- rep(NA, NROW(rval))
                missings[[v]][nas] <- natype
                rval[[v]][nas] <- NA
            }
            attr(rval, "missing") <- missings
        }
        else warning("'missing.type' only applicable to version >= 8 files")
    }
    convert_dt_c <- function(x) as.POSIXct((x + 0.1)/1000, origin = "1960-01-01")
    convert_dt_C <- function(x) {
        ls <- .leap.seconds + seq_along(.leap.seconds) + 315619200
        z <- (x + 0.1)/1000
        z <- z - rowSums(outer(z, ls, ">="))
        as.POSIXct(z, origin = "1960-01-01")
    }
    if (convert.dates) {
        ff <- attr(rval, "formats")
        dates <- if (attr(rval, "version") >= 8L) 
            grep("^%(-|)(d|td)", ff)
        else grep("%-*d", ff)
        base <- structure(-3653L, class = "Date")
        for (v in dates) rval[[v]] <- structure(base + rval[[v]], 
            class = "Date")
        for (v in grep("%tc", ff)) rval[[v]] <- convert_dt_c(rval[[v]])
        for (v in grep("%tC", ff)) rval[[v]] <- convert_dt_C(rval[[v]])
    }
    if (convert.factors %in% c(TRUE, NA)) {
        if (attr(rval, "version") == 5L) 
            warning("cannot read factor labels from Stata 5 files")
        else {
            ll <- attr(rval, "val.labels")
            tt <- attr(rval, "label.table")
            factors <- which(ll != "")
            for (v in factors) {
                labels <- tt[[ll[v]]]
                if (warn.missing.labels && is.null(labels)) {
                  warning(gettextf("value labels (%s) for %s are missing", 
                    sQuote(ll[v]), sQuote(names(rval)[v])), domain = NA)
                  next
                }
                if (!is.na(convert.factors)) {
                  if (!all(rval[[v]] %in% c(NA, NaN, tt[[ll[v]]]))) 
                    next
                }
                rval[[v]] <- factor(rval[[v]], levels = tt[[ll[v]]], 
                  labels = names(tt[[ll[v]]]))
            }
        }
    }
    att <- attributes(rval)
    class(rval) <- "data.frame"
    newatt <- attributes(rval)
    newatt <- c(newatt, att[!(names(att) %in% names(newatt))])
    attributes(rval) <- newatt
    rval
}
<bytecode: 0x10e035780>
<environment: namespace:foreign>

read.ssd

Arguments

  • libname
  • sectionnames
  • tmpXport
> read.ssd("/Users/uri/Downloads/music.sas7bdat")
Error in read.ssd("/Users/uri/Downloads/music.sas7bdat"): argument "sectionnames" is missing, with no default