From noreply at r-forge.r-project.org Mon Apr 6 23:11:15 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 6 Apr 2015 23:11:15 +0200 (CEST) Subject: [R-gregmisc-commits] r1625 - in pkg: BalloonPlotPaper SASxport SASxport/R SASxport/inst SASxport/man SASxport/src SASxport/tests SII SII/inst fork/src fork/tests gdata gdata/R gdata/inst gdata/inst/perl gdata/inst/perl/Spreadsheet gdata/inst/perl/Spreadsheet/ParseExcel gdata/inst/perl/Spreadsheet/ParseExcel/SaveParser gdata/inst/xls gdata/man gdata/tests gmodels gmodels/R gmodels/inst gmodels/man gplots gplots/R gplots/inst gplots/man gplots/tests gregmisc gregmisc/inst gtools gtools/R gtools/inst gtools/man Message-ID: <20150406211115.1B680183FB9@r-forge.r-project.org> Author: warnes Date: 2015-04-06 23:11:14 +0200 (Mon, 06 Apr 2015) New Revision: 1625 Added: pkg/gmodels/inst/ChangeLog pkg/gplots/inst/ChangeLog pkg/gregmisc/ChangeLog pkg/gregmisc/NEWS pkg/gregmisc/inst/ChangeLog pkg/gregmisc/inst/NEWS pkg/gtools/inst/ChangeLog Removed: pkg/gregmisc/NEWS Modified: pkg/BalloonPlotPaper/BalloonPlot.R pkg/BalloonPlotPaper/BalloonPlot.pdf pkg/BalloonPlotPaper/BalloonPlot.tex pkg/BalloonPlotPaper/Figure1.pdf pkg/BalloonPlotPaper/Figure2.pdf pkg/BalloonPlotPaper/Figure3.pdf pkg/BalloonPlotPaper/Figure4.pdf pkg/SASxport/DESCRIPTION pkg/SASxport/NAMESPACE pkg/SASxport/R/fstr.R pkg/SASxport/R/lookup.xport.R pkg/SASxport/R/make.formats.R pkg/SASxport/R/parseFormat.R pkg/SASxport/R/read.xport.R pkg/SASxport/R/write.xport.R pkg/SASxport/R/xport.R pkg/SASxport/R/xport.member.header.R pkg/SASxport/R/zzz.R pkg/SASxport/inst/NEWS pkg/SASxport/man/Alfalfa.Rd pkg/SASxport/man/SASxport-package.Rd pkg/SASxport/man/lookup.xport.Rd pkg/SASxport/man/read.xport.Rd pkg/SASxport/man/write.xport.Rd pkg/SASxport/src/SASxport.c pkg/SASxport/src/SASxport.h pkg/SASxport/src/ibm2ieee.c pkg/SASxport/src/ieee2ibm.c pkg/SASxport/src/init.c pkg/SASxport/src/test_fields.c pkg/SASxport/src/writeSAS.c pkg/SASxport/src/writeSAS.h pkg/SASxport/tests/Alfalfa_Test.R pkg/SASxport/tests/Alfalfa_Test.Rout.save pkg/SASxport/tests/Theoph.R pkg/SASxport/tests/Theoph.Rout.save pkg/SASxport/tests/cars.R pkg/SASxport/tests/cars.Rout.save pkg/SASxport/tests/testDates.R pkg/SASxport/tests/testDates.Rout.save pkg/SASxport/tests/testDuplicateNames.R pkg/SASxport/tests/testDuplicateNames.Rout.save pkg/SASxport/tests/testManyNames.R pkg/SASxport/tests/testManyNames.Rout.save pkg/SASxport/tests/testNegative.R pkg/SASxport/tests/testNegative.Rout.save pkg/SASxport/tests/testNumeric.R pkg/SASxport/tests/testNumeric.Rout.save pkg/SASxport/tests/testUnnamedComponents.R pkg/SASxport/tests/testUnnamedComponents.Rout.save pkg/SASxport/tests/test_as_is.R pkg/SASxport/tests/test_as_is.Rout.save pkg/SASxport/tests/test_fields.R pkg/SASxport/tests/test_fields.Rout.save pkg/SASxport/tests/xport.R pkg/SASxport/tests/xport.Rout.save pkg/SASxport/tests/xxx.R pkg/SASxport/tests/xxx.Rout.save pkg/SII/DESCRIPTION pkg/SII/inst/NEWS pkg/fork/src/fork.c pkg/fork/tests/test_many_fork_BSD.Rout.save pkg/fork/tests/test_many_fork_SysV.Rout.save pkg/fork/tests/test_many_fork_broken.Rout.save pkg/gdata/DESCRIPTION pkg/gdata/NAMESPACE pkg/gdata/R/aggregate.table.R pkg/gdata/R/installXLSXsupport.R pkg/gdata/R/keep.R pkg/gdata/R/ll.R pkg/gdata/R/mapLevels.R pkg/gdata/R/nobs.R pkg/gdata/R/sheetCount.R pkg/gdata/R/trim.R pkg/gdata/R/unknown.R pkg/gdata/R/xls2sep.R pkg/gdata/R/xlsFormats.R pkg/gdata/inst/NEWS pkg/gdata/inst/perl/Spreadsheet/ParseExcel.pm pkg/gdata/inst/perl/Spreadsheet/ParseExcel/Cell.pm pkg/gdata/inst/perl/Spreadsheet/ParseExcel/Dump.pm pkg/gdata/inst/perl/Spreadsheet/ParseExcel/FmtDefault.pm pkg/gdata/inst/perl/Spreadsheet/ParseExcel/FmtJapan.pm pkg/gdata/inst/perl/Spreadsheet/ParseExcel/FmtJapan2.pm pkg/gdata/inst/perl/Spreadsheet/ParseExcel/FmtUnicode.pm pkg/gdata/inst/perl/Spreadsheet/ParseExcel/Font.pm pkg/gdata/inst/perl/Spreadsheet/ParseExcel/Format.pm pkg/gdata/inst/perl/Spreadsheet/ParseExcel/SaveParser.pm pkg/gdata/inst/perl/Spreadsheet/ParseExcel/SaveParser/Workbook.pm pkg/gdata/inst/perl/Spreadsheet/ParseExcel/SaveParser/Worksheet.pm pkg/gdata/inst/perl/Spreadsheet/ParseExcel/Utility.pm pkg/gdata/inst/perl/Spreadsheet/ParseExcel/Workbook.pm pkg/gdata/inst/perl/Spreadsheet/ParseExcel/Worksheet.pm pkg/gdata/inst/perl/install_modules.pl pkg/gdata/inst/perl/module_tools.pl pkg/gdata/inst/perl/sheetCount.pl pkg/gdata/inst/perl/supportedFormats.pl pkg/gdata/inst/perl/xls2csv.pl pkg/gdata/inst/xls/ExampleExcelFile.xls pkg/gdata/inst/xls/ExampleExcelFile.xlsx pkg/gdata/man/gdata-package.Rd pkg/gdata/man/read.xls.Rd pkg/gdata/man/sheetCount.Rd pkg/gdata/tests/test.read.xls.R pkg/gdata/tests/test.read.xls.Rout.save pkg/gdata/tests/tests.write.fwf.Rout.save pkg/gmodels/DESCRIPTION pkg/gmodels/NAMESPACE pkg/gmodels/R/ci.R pkg/gmodels/R/estimable.R pkg/gmodels/R/estimable.mlm.R pkg/gmodels/inst/NEWS pkg/gmodels/man/ci.Rd pkg/gmodels/man/estimable.Rd pkg/gplots/DESCRIPTION pkg/gplots/NAMESPACE pkg/gplots/R/bandplot.R pkg/gplots/R/barplot2.R pkg/gplots/R/heatmap.2.R pkg/gplots/R/overplot.R pkg/gplots/R/plot.venn.R pkg/gplots/R/plotmeans.R pkg/gplots/R/sinkplot.R pkg/gplots/R/venn.R pkg/gplots/inst/NEWS pkg/gplots/man/bandplot.Rd pkg/gplots/man/barplot2.Rd pkg/gplots/man/ci2d.Rd pkg/gplots/man/heatmap.2.Rd pkg/gplots/man/hist2d.Rd pkg/gplots/man/lowess.Rd pkg/gplots/man/plotmeans.Rd pkg/gplots/man/sinkplot.Rd pkg/gplots/tests/heatmap2Test.R pkg/gplots/tests/heatmap2Test.Rout.save pkg/gregmisc/DESCRIPTION pkg/gtools/DESCRIPTION pkg/gtools/NAMESPACE pkg/gtools/R/addLast.R pkg/gtools/R/binsearch.R pkg/gtools/R/checkRVersion.R pkg/gtools/R/deprecated.R pkg/gtools/R/keywords.R pkg/gtools/R/mixedsort.R pkg/gtools/R/smartbind.R pkg/gtools/inst/NEWS pkg/gtools/man/gtools-deprecated.Rd pkg/gtools/man/keywords.Rd pkg/gtools/man/logit.Rd pkg/gtools/man/smartbind.Rd Log: Bring RForge codebase up to latest version on SourceForge. Modified: pkg/BalloonPlotPaper/BalloonPlot.R =================================================================== --- pkg/BalloonPlotPaper/BalloonPlot.R 2015-02-24 09:36:37 UTC (rev 1624) +++ pkg/BalloonPlotPaper/BalloonPlot.R 2015-04-06 21:11:14 UTC (rev 1625) @@ -1,7 +1,7 @@ #### ## Figure 1 #### -.libPaths("~warneg/Rlib") +##.libPaths("~warneg/Rlib") library(gplots) data(Titanic) Modified: pkg/BalloonPlotPaper/BalloonPlot.pdf =================================================================== (Binary files differ) Modified: pkg/BalloonPlotPaper/BalloonPlot.tex =================================================================== --- pkg/BalloonPlotPaper/BalloonPlot.tex 2015-02-24 09:36:37 UTC (rev 1624) +++ pkg/BalloonPlotPaper/BalloonPlot.tex 2015-04-06 21:11:14 UTC (rev 1625) @@ -268,11 +268,11 @@ to the development of \code{balloonplot}, as well as for the code for displaying the row and column sums. -\address{Gregory R. Warnes, Center for Biodefense Immune Modeling, - Univeristy of Rochester, Rochester, NY, USA\\ -\email{warnes at bst.rochester.edu}\\ - Nitin Jain, Smith Hanley Inc, USA\\ -\email{nitin.jain at pfizer.com}} +\address{Gregory R. Warnes, Gregory R. Warnes Statistical Consulting, + Pittsford, NY, USA\\ +\email{greg at warnes.net}\\ + Nitin Jain, Goldman Sachs, USA\\ +\email{emailnitinjain at gmail.com}} \begin{thebibliography}{3} Modified: pkg/BalloonPlotPaper/Figure1.pdf =================================================================== (Binary files differ) Modified: pkg/BalloonPlotPaper/Figure2.pdf =================================================================== (Binary files differ) Modified: pkg/BalloonPlotPaper/Figure3.pdf =================================================================== (Binary files differ) Modified: pkg/BalloonPlotPaper/Figure4.pdf =================================================================== (Binary files differ) Modified: pkg/SASxport/DESCRIPTION =================================================================== --- pkg/SASxport/DESCRIPTION 2015-02-24 09:36:37 UTC (rev 1624) +++ pkg/SASxport/DESCRIPTION 2015-04-06 21:11:14 UTC (rev 1625) @@ -1,36 +1,42 @@ Package: SASxport Type: Package Title: Read and Write SAS XPORT Files -Version: 1.3.0 -Date: 2012-06-29 +Version: 1.5.0 +Date: 2014-07-21 Description: This package provides functions for reading, listing - the contents of, and writing SAS xport format files. + the contents of, and writing SAS xport format files. The functions support reading and writing of either individual data frames or sets of data frames. Further, a mechanism has been provided for customizing how - variables of different data types are stored. -Author: + variables of different data types are stored. +Author: Unless otherwise noted, the contents of this package were written by Gregory R. Warnes and are provided under the - terms of the GNU General Public License, version 2.0 or later. + terms of the GNU General Public License, version 2.0 or later. -- - The files 'ieee2ibm.c' and 'ibm2ieee.c' were extracted from BRL-CAD, - file /brlcad/src/libbu/htond.c written by Michael John Muuss, - Copyright (c) 2004-2007 United States Government as represented by - the U.S. Army Research Laboratory, and is utilized and redistributed - under the terms of the GNU Lesser General Public License, version 2.1. + The files 'src/ieee2ibm.c' and 'src/ibm2ieee.c' were extracted from + BRL-CAD file /brlcad/src/libbu/htond.c written by Michael John + Muuss, Copyright (c) 2004-2007 United States Government as + represented by the U.S. Army Research Laboratory, and is utilized + and redistributed under the terms of the GNU Lesser General Public + License, version 2.1. -- - The files 'AFirst.lib.s', 'all.is.numeric.R', - 'importConvertDateTime.R', 'in.opererator.R', 'makeNames.R', - 'read.xport.R', and 'testDateTime.R' are copied or adapted from the - 'Hmisc' package created by Frank E. Harrell, Jr. + The files 'R/AFirst.lib.s', 'R/all.is.numeric.R', + 'R/importConvertDateTime.R', 'R/in.opererator.R', 'R/makeNames.R', + 'R/read.xport.R', and 'R/testDateTime.R' are copied or adapted from the + 'Hmisc' package created by Frank E. Harrell, Jr. , and are utilized and redistributed under - the terms of the GNU General Public License, version 2.0 or later. - -- + the terms of the GNU General Public License, version 2.0 or later. + -- + The files 'R/xport.R', 'src/SASxport.c', 'src/SASxport.h', and + 'src/foreign.h' are copied or adapted from the R 'foreign' package + created by Douglas M. Bates and Saikat DebRoy + , and are utilized and redistributed under the + terms of the GNU General Public License, version 2.0 or later. + -- The creation of this package was partially funded by Metrum Institute - . + . Maintainer: Gregory R. Warnes License: GPL-2 -Depends: R (>= 2.4.0) -Imports: chron +Depends: R (>= 2.4.0), chron, Hmisc URL: http://www.warnes.net, http://metruminstitute.org Modified: pkg/SASxport/NAMESPACE =================================================================== --- pkg/SASxport/NAMESPACE 2015-02-24 09:36:37 UTC (rev 1624) +++ pkg/SASxport/NAMESPACE 2015-04-06 21:11:14 UTC (rev 1625) @@ -2,24 +2,28 @@ importFrom(chron, chron, times) importFrom(utils, packageDescription) +importFrom(Hmisc, label, label.default, "label<-", "label<-.default") export( toSAS, lookup.xport, read.xport, write.xport, - "label", - "label<-", + ## "label", + ## "label<-", makeSASNames, - + "SASformat", "SASformat<-", - + "SASiformat", - "SASiformat<-" - ) + "SASiformat<-", + "SAStype", + "SAStype<-" +) + S3method(toSAS, numeric) S3method(toSAS, logical) S3method(toSAS, character) @@ -29,13 +33,15 @@ S3method(toSAS, Date) S3method(toSAS, default) -S3method(label, default) +## S3method(label, default) S3method(SASformat, default) S3method(SASiformat, default) +S3method(SAStype, default) -S3method("label<-", default) +## S3method("label<-", default) S3method("SASformat<-", default) S3method("SASiformat<-", default) +S3method("SAStype<-", default) S3method(print, lookup.xport) S3method(summary, lookup.xport) Modified: pkg/SASxport/R/fstr.R =================================================================== --- pkg/SASxport/R/fstr.R 2015-02-24 09:36:37 UTC (rev 1624) +++ pkg/SASxport/R/fstr.R 2015-04-06 21:11:14 UTC (rev 1625) @@ -12,6 +12,8 @@ else return( paste(name[i], length[i], '.', digits[i], sep='' ) ) } - sapply( 1:length(name), inner) - + if(length(name)>0) + sapply( 1:length(name), inner) + else + character(0) } Modified: pkg/SASxport/R/lookup.xport.R =================================================================== --- pkg/SASxport/R/lookup.xport.R 2015-02-24 09:36:37 UTC (rev 1624) +++ pkg/SASxport/R/lookup.xport.R 2015-04-06 21:11:14 UTC (rev 1625) @@ -37,6 +37,7 @@ "label" ) ]) + if(nrow(ret)==0) ret[1,] <- NA # ensure at least one row cbind(dataset=XX, ret, nobs=df$length) } Modified: pkg/SASxport/R/make.formats.R =================================================================== --- pkg/SASxport/R/make.formats.R 2015-02-24 09:36:37 UTC (rev 1624) +++ pkg/SASxport/R/make.formats.R 2015-04-06 21:11:14 UTC (rev 1625) @@ -76,14 +76,16 @@ else formatName <- fname varLevels <- levels(var) - formats <- empty.format.table() - for( j in 1:nlevels(var) ) - formats <- add.format.entry(formats, - formatName, - j, - j, - varLevels[j] - ) + formats <- empty.format.table() + + if(nlevels(var)>0) + for( j in 1:nlevels(var) ) + formats <- add.format.entry(formats, + formatName, + j, + j, + varLevels[j] + ) formats } Modified: pkg/SASxport/R/parseFormat.R =================================================================== --- pkg/SASxport/R/parseFormat.R 2015-02-24 09:36:37 UTC (rev 1624) +++ pkg/SASxport/R/parseFormat.R 2015-04-06 21:11:14 UTC (rev 1625) @@ -3,7 +3,7 @@ { retval <- list("name"="", "len"=0, "digits"=0) - + if( !is.null(format) && (length(format)==1) && (format > "") ) { index <- regexpr("[0-9]+", format) @@ -16,9 +16,9 @@ else { retval$name <- substr(format,0,index-1)[1] - - lenStr <- substr(format,index, nchar(format)) - + + lenStr <- substr(format, index, nchar(format)) + index <- regexpr("\\.", lenStr) if(index==-1) { @@ -31,10 +31,10 @@ retval$digits <- as.numeric(substr(lenStr, index+1, nchar(lenStr))) } } - + if(is.na(retval$len)) retval$len <- 0 if(is.na(retval$digits)) retval$digits <- 0 - + } return(retval) Modified: pkg/SASxport/R/read.xport.R =================================================================== --- pkg/SASxport/R/read.xport.R 2015-02-24 09:36:37 UTC (rev 1624) +++ pkg/SASxport/R/read.xport.R 2015-04-06 21:11:14 UTC (rev 1625) @@ -1,5 +1,5 @@ ## -## Code originally from Frank Harrell's 'Hmisc' library: +## Code originally from Frank Harrell's 'Hmisc' library: ## http://biostat.mc.vanderbilt.edu/twiki/bin/view/Main/Hmisc ## Copied with permission on 2007-08-04 ## @@ -32,7 +32,7 @@ if(length(grep('http://', file))>0 || length(grep('ftp://', file))>0 ) { - scat("Downloading file...") + scat("Downloading file...") tf <- tempfile() download.file(file, tf, mode='wb', quiet=TRUE) file <- tf @@ -44,10 +44,13 @@ file.header <- substr(file.header, start=1, stop=nchar(xport.file.header) ) if( !identical(xport.file.header, file.header) ) stop("The specified file does not start with a SAS xport file header!") - + scat("Extracting data file information...") dsinfo <- lookup.xport.inner(file) + dsLabels <- sapply(dsinfo, label) + dsTypes <- sapply(dsinfo, SAStype) + if(length(keep)) whichds <- toupper(keep) else @@ -62,7 +65,7 @@ names(ds) <- make.unique(names(ds)) } - + if( (length(keep)>0 || length(drop)>0) ) ds <- ds[whichds] @@ -79,7 +82,7 @@ fds <- fds[1] } } - + finfo <- NULL if(length(formats) || length(fds)) { if(length(formats)) @@ -99,13 +102,13 @@ else names.tolower <- function(x) x - dsn <- tolower(which.regular) + dsn <- names.tolower(which.regular) res <- vector('list', nds) names(res) <- gsub('_','.',dsn) - possiblyConvertChar <- (is.logical(as.is) && !as.is) || + possiblyConvertChar <- (is.logical(as.is) && !as.is) || (is.numeric(as.is) && as.is > 0) j <- 0 for(k in which.regular) { @@ -117,90 +120,91 @@ else ds[[k]] scat('.') - - if(!length(w)) { - scat('Empty dataset', k, 'ignored\n') - next - } + label(w, self=TRUE) <- dsLabels[k] + names(label(w, self=TRUE)) <- NULL + SAStype(w) <- dsTypes[k] + names(SAStype(w)) <- NULL + nam <- names.tolower(makeNames(names(w), allow=name.chars)) names(w) <- nam dinfo <- dsinfo[[k]] - fmt <- sub('^\\$','',dinfo$format) + fmt <- dinfo$format formats <- fstr( fmt, dinfo$flength, dinfo$fdigits) - ifmt <- sub('^\\$','',dinfo$iformat) + ifmt <- dinfo$iformat iformats <- fstr( ifmt, dinfo$iflength, dinfo$ifdigits) lab <- dinfo$label - + ndinfo <- names.tolower(makeNames(dinfo$name, allow=name.chars)) names(lab) <- names(fmt) <- names(formats) <- names(iformats) <- ndinfo - for(i in 1:length(w)) { - changed <- FALSE - x <- w[[i]] - fi <- fmt[nam[i]]; - names(fi) <- NULL - if(fi != '' && length(finfo) && (fi %in% names(finfo))) { - f <- finfo[[fi]] - if(length(f)) { ## may be NULL because had a range in format - x <- factor(x, f$value, f$label) - attr(x, 'SASformat') <- fi - changed <- TRUE + if(length(w)>0) + for(i in 1:length(w)) { + changed <- FALSE + x <- w[[i]] + fi <- fmt[nam[i]]; + names(fi) <- NULL + if(fi != '' && length(finfo) && (fi %in% names(finfo))) { + f <- finfo[[fi]] + if(length(f)) { ## may be NULL because had a range in format + x <- factor(x, f$value, f$label) + attr(x, 'SASformat') <- fi + changed <- TRUE + } } - } - if(is.numeric(x)) { - if(fi %in% sasdateform) { - x <- importConvertDateTime(x, 'date', 'sas') - changed <- TRUE - } else if(fi %in% sastimeform) { - x <- importConvertDateTime(x, 'time', 'sas') - changed <- TRUE - } else if(fi %in% sasdatetimeform) { - x <- importConvertDateTime(x, 'datetime', 'sas') - changed <- TRUE - } else if(force.integer) { - if(all(is.na(x))) { - storage.mode(x) <- 'integer' + if(is.numeric(x)) { + if(fi %in% sasdateform) { + x <- importConvertDateTime(x, 'date', 'sas') changed <- TRUE - } else if(max(abs(x),na.rm=TRUE) <= (2^31-1) && - all(floor(x) == x, na.rm=TRUE)) { - storage.mode(x) <- 'integer' + } else if(fi %in% sastimeform) { + x <- importConvertDateTime(x, 'time', 'sas') changed <- TRUE + } else if(fi %in% sasdatetimeform) { + x <- importConvertDateTime(x, 'datetime', 'sas') + changed <- TRUE + } else if(force.integer) { + if(all(is.na(x))) { + storage.mode(x) <- 'integer' + changed <- TRUE + } else if(max(abs(x),na.rm=TRUE) <= (2^31-1) && + all(floor(x) == x, na.rm=TRUE)) { + storage.mode(x) <- 'integer' + changed <- TRUE } + } + } else if(possiblyConvertChar && is.character(x)) { + if((is.logical(as.is) && !as.is) || + (is.numeric(as.is) && length(unique(x)) < as.is*length(x))) { + x <- factor(x, exclude='') + changed <- TRUE + } } - } else if(possiblyConvertChar && is.character(x)) { - if((is.logical(as.is) && !as.is) || - (is.numeric(as.is) && length(unique(x)) < as.is*length(x))) { - x <- factor(x, exclude='') - changed <- TRUE + + lz <- lab[nam[i]] + if(!is.null(lz) && length(lz)>0 && !is.na(lz) && lz != '') { + names(lz) <- NULL + label(x) <- lz + changed <- TRUE } - } - lz <- lab[nam[i]] - if(!is.null(lz) && length(lz)>0 && !is.na(lz) && lz != '') { - names(lz) <- NULL - label(x) <- lz - changed <- TRUE - } + if(nam[i] %in% names(formats) && formats[nam[i]] > "" ) + { + SASformat(x) <- formats[[nam[i]]] + changed <- TRUE + } - if( formats[nam[i]] > "" ) - { - SASformat(x) <- formats[[nam[i]]] + if(nam[i] %in% names(iformats) && iformats[nam[i]] > "" ) + { + SASformat(x) <- formats[[nam[i]]] changed <- TRUE - } - - if( iformats[nam[i]] > "" ) - { - SASformat(x) <- formats[[nam[i]]] - changed <- TRUE - } + } - if(changed) - w[[i]] <- x - } + if(changed) + w[[i]] <- x + } scat('.') @@ -212,15 +216,17 @@ if( include.formats ) { nds <- nds+1 - if( length(fds)>0 ) + if( length(fds)>0 ) res$"FORMATS" <- ds[[fds]] else res$FORMATS <- empty.format.table() } - if(nds > 1 || as.list) res else + if(class(w)=="list") + w[[1]] + else w } Modified: pkg/SASxport/R/write.xport.R =================================================================== --- pkg/SASxport/R/write.xport.R 2015-02-24 09:36:37 UTC (rev 1624) +++ pkg/SASxport/R/write.xport.R 2015-04-06 21:11:14 UTC (rev 1625) @@ -1,13 +1,13 @@ write.xport <- function(..., list=base::list(), - file = stop("'file' must be specified"), + file = stop("'file' must be specified"), verbose=FALSE, sasVer="7.00", osType, cDate=Sys.time(), formats=NULL, autogen.formats=TRUE - ) + ) { ## Handle verbose option ## @@ -31,10 +31,10 @@ dotNames <- names(dotList) if(is.null(dotNames)) dotNames <- rep("", length(dotList)) - if(length(dotList)>0) + if(length(dotList)>0) { ## Get data frame names from ... in function call, but don't - ## clobber any explicitly provided names + ## clobber any explicitly provided names mc <- match.call() mc$file <- NULL mc$verbose <- NULL @@ -45,8 +45,8 @@ mc$autogen.formats <- NULL mc[[1]] <- NULL # note we *do not* mask off format argument so it will get - # magically included if present. - + # magically included if present. + mc <- as.character(mc) badNames <- which(is.na(dotNames) | dotNames<="") @@ -59,7 +59,7 @@ listNames <- rep("", length(list)) dfList <- c(dotList, list) dfNames <- c(dotNames, listNames) - + ## check for and handle or empty names ## badNames <- which(is.na(dfNames) | dfNames<="") if(length(badNames)>0) @@ -79,7 +79,7 @@ if(length(not.df)==1) stop(paste("'", dfNames[not.df], "'"), " is not a data.frame object.") - else + else stop(paste("'", dfNames[not.df], "'", sep="", collapse=", "), " are not data.frame objects.") ## @@ -111,8 +111,8 @@ ####### scat("opening file ...") - if (is.character(file)) - if (file == "") + if (is.character(file)) + if (file == "") file <- stdout() else { file <- file(description=file, open="wb") @@ -123,8 +123,8 @@ if(file==stdout()) out <- function(...) { - cat("ASCII: ", rawToDisplay(...), "") - cat("HEX: ", ..., "") + cat("ASCII: ", rawToDisplay(...), "\n") + cat("HEX: ", ..., "\n") } else out <- function(...) writeBin( ..., raw(), con=file) @@ -132,10 +132,10 @@ scat("Write file header ...") out( xport.file.header( cDate=cDate, sasVer=sasVer, osType=osType ) ) scat("Done.") - + for(i in dfNames) { - + df <- dfList[[i]] if(is.null(colnames(df))) @@ -149,20 +149,26 @@ dfList[[i]] <- df } - + colnames(dfList[[i]]) <- colnames(df) <- varNames <- makeSASNames(colnames(df)) - - offsetTable <- data.frame("name"=varNames, "len"=NA, "offset"=NA ) + + offsetTable <- data.frame("name"=varNames, + "len"=rep(NA, length(varNames)), + "offset"=rep(NA, length(varNames)) ) rownames(offsetTable) <- offsetTable[,"name"] + dfLabel <- label(df, default="", self=TRUE ) + dfType <- SAStype(df, default="") + scat("Write data frame header ...") - out( xport.member.header(dfName=i, cDate=cDate, sasVer=sasVer, osType=osType ) ) + out( xport.member.header(dfName=i, cDate=cDate, sasVer=sasVer, osType=osType, + dfLabel=dfLabel, dfType=dfType) ) scat("Done.") - scat("Write variable informaton block header ...") + scat("Write variable information block header ...") out( xport.namestr.header( nvar=ncol(df) ) ) scat("Done.") - + scat("Write entries for variable information block ...") lenIndex <- 0 varIndex <- 1 @@ -190,15 +196,10 @@ offsetTable[i, "len"] <- varLen offsetTable[i, "offset"] <- lenIndex - - - # parse format and iformat formatInfo <- parseFormat(varFormat) iFormatInfo <- parseFormat(varIFormat) - - - + # write the entry out( xport.namestr( @@ -207,7 +208,7 @@ varNum = varIndex, varPos = lenIndex, varLength = varLen, - varLabel = varLabel, + varLabel = varLabel, fName = formatInfo$name, fLength = formatInfo$len, fDigits = formatInfo$digits, @@ -226,8 +227,8 @@ # Space-fill to 80 character record end fillSize <- 80 - (spaceUsed %% 80) - if(fillSize==80) fillSize <- 0 - out( xport.fill( TRUE, fillSize ) ) + if(fillSize==80) fillSize <- 0 + out( xport.fill( TRUE, fillSize ) ) scat("Write header for data block ...") out( xport.obs.header() ) @@ -235,34 +236,37 @@ scat("Write data ... "); spaceUsed <- 0 - for(i in 1:nrow(df) ) - for(j in 1:ncol(df) ) + if(nrow(df)>0) { - val <- df[i,j] - valLen <- offsetTable[j,"len"] + for(i in 1:nrow(df) ) + for(j in 1:ncol(df) ) + { + val <- df[i,j] + valLen <- offsetTable[j,"len"] - scat("i=", i, " j=", j, " value=", val, " len=", valLen, ""); - if(is.character( val )) - { - out(xport.character(val, width=valLen ) ) + scat("i=", i, " j=", j, " value=", val, " len=", valLen, ""); + if(is.character( val )) + { + out(xport.character(val, width=valLen ) ) + } + else + out( xport.numeric( val ) ) + + spaceUsed <- spaceUsed + valLen } - else - out( xport.numeric( val ) ) + } - spaceUsed <- spaceUsed + valLen - } - fillSize <- 80 - (spaceUsed %% 80) if(fillSize==80) fillSize <- 0 out( xport.fill(TRUE, fillSize ) ) - + scat("Done.") } scat("Closing file ...") - if (is.character(file)) + if (is.character(file)) if (file != "") - { + { close(file) on.exit() } Modified: pkg/SASxport/R/xport.R =================================================================== --- pkg/SASxport/R/xport.R 2015-02-24 09:36:37 UTC (rev 1624) +++ pkg/SASxport/R/xport.R 2015-04-06 21:11:14 UTC (rev 1625) @@ -23,12 +23,11 @@ lookup.xport.inner <- function(file) .Call(xport_info, file) - read.xport.inner <- function(file, stringsAsFactors=FALSE) { data.info <- lookup.xport.inner(file) ans <- .Call(xport_read, file, data.info) - if (length(ans) == 1) - as.data.frame(ans[[1]], stringsAsFactors=stringsAsFactors) + if (length(ans) == 1L) + as.data.frame(ans[[1L]], stringsAsFactors=stringsAsFactors) else lapply(ans, as.data.frame, stringsAsFactors=stringsAsFactors) } Modified: pkg/SASxport/R/xport.member.header.R =================================================================== --- pkg/SASxport/R/xport.member.header.R 2015-02-24 09:36:37 UTC (rev 1624) +++ pkg/SASxport/R/xport.member.header.R 2015-04-06 21:11:14 UTC (rev 1625) @@ -1,12 +1,15 @@ `xport.member.header` <- -function( dfName, cDate=Sys.time(), mDate=cDate, sasVer="7.00", osType="Unknown" ) +function(dfName, cDate=Sys.time(), mDate=cDate, sasVer="7.00", osType="Unknown", + dfLabel="", dfType="" ) { .C("fill_member_header", dfName = toupper(as.character(dfName)), # Name of data set sasVer = toupper(as.character(sasVer)), # SAS version number osType = as.character(osType), # Operating System (can include lowercase) - cDate = xport.dateFMT(cDate), # Creation date - mDate = xport.dateFMT(mDate), # modification date + cDate = xport.dateFMT(cDate), # Creation date + mDate = xport.dateFMT(mDate), # modification date + dfLabel= as.character(dfLabel), # Data set label + dfType = as.character(dfType), # Data set type PACKAGE="SASxport" ) Modified: pkg/SASxport/R/zzz.R =================================================================== --- pkg/SASxport/R/zzz.R 2015-02-24 09:36:37 UTC (rev 1624) +++ pkg/SASxport/R/zzz.R 2015-04-06 21:11:14 UTC (rev 1625) @@ -9,13 +9,6 @@ cat("\n") } - - -.First.lib <- function(lib, pkg) { - library.dynam("SASxport", pkg, lib) - loadMessage() -} - .onLoad <- function(lib, pkg) { loadMessage() } Modified: pkg/SASxport/inst/NEWS =================================================================== --- pkg/SASxport/inst/NEWS 2015-02-24 09:36:37 UTC (rev 1624) +++ pkg/SASxport/inst/NEWS 2015-04-06 21:11:14 UTC (rev 1625) @@ -1,3 +1,105 @@ +Version 1.5.0 - 2014-07-21 +-------------------------- + +Bug fixes: + +- Now works properly on big-endian systems such as the PowerPC, + Spark. (Reported by Brian Ripley )x + +- Explicitly cast left bit shifts to avoid undefined C language + behavior. (Reported by Brian Ripley) + +- Resolve problem in accessing "Hmisc::label.default<-" if + SASxport::read.xport is called without loading SASxport. (Reported + by Dominic Comtois) + +- 'read.xport' now preserves '$' at the beginning of SAS character + format and iformat strings. (Reported by Dominic Comtois) + +- 'read.xport' argument names.tolower was not being honored for + dataset names. (Reported by Dominic Comtois) + +Other changes: + +- Modified several test files to display generated .xpt data so that + issues can be more easily detected and diagnosed. + +- C code cleanup and reorgaization to improve clarity. + + +Version 1.4.0 - 2014-04-09 +-------------------------- + +API Change: + +- SASxport now relies on the 'label' methods defined by the Hmisc + package instead of defining its own. + +Bug fixes: + +- The 'read.xport' and 'write.xport' functions were failing when both + the SASxport and the Hmisc packages were loaded due to conflicts + between the label methods defined by each package. This has been + resolved by removing the label methods from SASxport and using those + from Hmisc instead. + + +Version 1.3.6 2013-10-09 +------------------------ + +Bug fixes: + +- In manual pages for read.xport() and lookup.xporT(): Update URL for + 'test2.xpt', and use a local copy for executed example code. + +Version 1.3.5 2013-06-14 +------------------------ + +Bug fixes: + +- read.xport() and write.xport() now properly handle empty + dataset/dataframe objects. + +Version 1.3.4 2013-05-31 +------------------------ + +Bug fixes: + +- Correct error in write.xport when a factor contains only NA entries. + +Other Changes: + +- Package test scripts now use a fixed timezone to prevent unhelpful warnings. + +Version 1.3.2 2013-05-11 +------------------------ + +New features: + +- dataset label and type are now supported. See write.xport() and + read.xport() for examples. + +Bug fixes: + +- Integrate patch from foreign package to properly handle xport files + with datasets that end exactly on an 80-byte record boundry & add + corresponding test file. + +- Replace file.path(path.package(...)) with system.file(...) + +Changes: + +- Remove oboslete .First.lib() function + +- Replace file.path(path.package(...)) with system.file(...) + +Version 1.3.1 2013-03-24 +------------------------ + +Changes: + +- Replace use of depreciated .path.package() with path.package() for R 3.0.0. + Version 1.3.0 2012-06-27 ------------------------ @@ -37,7 +139,7 @@ Bug fixes: - Apply patches to fix problems on 64 bit platforms, as sumitted by - Brian Ripley. + Brian Ripley. Version 1.2.1 2007-11-05 @@ -63,27 +165,27 @@ - Copies of the code for foreign::read.xport and foreign::lookup.xport is now part of the SASxport package, permitting extension to these functions as needed, and removing the dependency on the foreign - package. + package. - Overflow of SASxport numeric format values, which have a smaller range than IEEE 754 numeric values now standard, now generates NAN - instead of 0.0. + instead of 0.0. Bug Fixes: - Fix for problem storing negative numbers. -- SAS format length and digit information is now properly captured +- SAS format length and digit information is now properly captured by read.xport(). This is supported by an improved version of - lookup.xport(). + lookup.xport(). -- SAS format information was not being properly utilized when more +- SAS format information was not being properly utilized when more than one format was present. - Improved handling of SAS date formats - + Other: - Test routines added to test handling of numeric values. @@ -95,7 +197,7 @@ - Display support information at package startup -Version 1.1.0 - +Version 1.1.0 - ------------------------- New Features: @@ -133,7 +235,7 @@ New features: - read.xport's names.tolower argument now defaults to FALSE so that - variable (and data set) names are now left as uppercase. + variable (and data set) names are now left as uppercase. - Improved crediting of BRL-CAD source code @@ -143,7 +245,7 @@ Other: -- Augmented ieee2ibm code with corresponding ibm2ieee code for +- Augmented ieee2ibm code with corresponding ibm2ieee code for completeness. @@ -152,7 +254,7 @@ New Features: -- Replaced IEEE to IBM translation code with GPL'ed version from BPL-CAD. +- Replaced IEEE to IBM translation code with GPL'ed version from BPL-CAD. Bug Fixes: Modified: pkg/SASxport/man/Alfalfa.Rd =================================================================== --- pkg/SASxport/man/Alfalfa.Rd 2015-02-24 09:36:37 UTC (rev 1624) +++ pkg/SASxport/man/Alfalfa.Rd 2015-04-06 21:11:14 UTC (rev 1625) @@ -30,7 +30,7 @@ # go were the data is... here <- getwd() -setwd(file.path(.path.package("SASxport"),"extdata")) +setwd(system.file("extdata",package="SASxport")) # Description of the file contents lookup.xport("Alfalfa.xpt") Modified: pkg/SASxport/man/SASxport-package.Rd =================================================================== --- pkg/SASxport/man/SASxport-package.Rd 2015-02-24 09:36:37 UTC (rev 1624) +++ pkg/SASxport/man/SASxport-package.Rd 2015-04-06 21:11:14 UTC (rev 1625) @@ -12,7 +12,7 @@ \details{ The \code{read.xport} function reads SAS xport formatted files, augmenting the functionality of the \code{\link[foreign]{read.xport}} - function provided in the 'foreign' package with additional features + function provided in the 'foreign' package with additional features, borrowed from \code{\link[Hmisc]{sasxport.get}} in Frank Harrell's 'Hmisc' package. Namely, variables are properly coerced into the types specified by the format field. All standard numeric and string @@ -21,7 +21,10 @@ in the xport file via: \preformatted{ PROC FORMAT CNTLOUT=format; -} + } + In addition, labels are supported for variable and data frames, as + are dataset 'types'. + The \code{write.xport} function writes one or more data sets into a SAS xport formatted file. Standard R data types, including date and time objects (e.g. \code{Date}, and \code{POSIX.t}) are stored with @@ -57,19 +60,25 @@ are provided under the terms of the GNU General Public License, version 2.0 or later. - The file 'htond.c' is extracted from BRL-CAD - \url{http://www.brlcad.org/}, written by Michael John Muuss, and is - Copyright (c) 2004-2007 United States Government as represented by - the U.S. Army Research Laboratory, and is utilized and redistributed - under the terms of the GNU Lesser General Public License, version 2.1. + The files 'src/ieee2ibm.c' and 'src/ibm2ieee.c' were extracted from [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/r-gregmisc -r 1625