[R-gregmisc-users] SF.net SVN: r-gregmisc: [1109] trunk/SASxport/tests
Brought to you by:
warnes
From: <wa...@us...> - 2007-08-03 00:35:19
|
Revision: 1109 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1109&view=rev Author: warnes Date: 2007-08-02 17:35:07 -0700 (Thu, 02 Aug 2007) Log Message: ----------- Add more tests Added Paths: ----------- trunk/SASxport/tests/cars.R trunk/SASxport/tests/datetime.xpt trunk/SASxport/tests/testDates.R trunk/SASxport/tests/xxx.R Added: trunk/SASxport/tests/cars.R =================================================================== --- trunk/SASxport/tests/cars.R (rev 0) +++ trunk/SASxport/tests/cars.R 2007-08-03 00:35:07 UTC (rev 1109) @@ -0,0 +1,25 @@ +library(SASxport) + + +cars <- read.table(file="cars.sas", skip=3, nrows=26, + col.names=c("MAKE","PRICE","MPG","REP78","FOREIGN"), + header=F) + +head(cars, n=5) + +summary(cars) + +write.xport(cars, + filename="cars2.xpt", + cDate=strptime("28JUL07: 20:59:49", format="%d%b%y:%H:%M:%S"), + osType="SunOS", + sasVer="9.1" +) + + +## Load both files back in as raw data +a.1 <- readBin( con="cars.xpt", what=raw(), n=1e5) +a.2 <- readBin( con="cars2.xpt", what=raw(), n=1e5) + +## Test that the files are identical +assert( all(a.1 == a.2) ) Added: trunk/SASxport/tests/datetime.xpt =================================================================== (Binary files differ) Property changes on: trunk/SASxport/tests/datetime.xpt ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/SASxport/tests/testDates.R =================================================================== --- trunk/SASxport/tests/testDates.R (rev 0) +++ trunk/SASxport/tests/testDates.R 2007-08-03 00:35:07 UTC (rev 1109) @@ -0,0 +1,23 @@ +library(SASxport) + +## Create a small data set containing dates, times, and date-times + +dates <- c("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92") +times <- c("23:03:20", "22:29:56", "01:03:30", "18:21:03", "16:56:26") + + +temp <- data.frame(x=c(1, 2, 3, 4, 5 ), + y=c('a', 'B', 'c', 'd', 'e' ), + dates=strptime(dates, "%m/%d/%y"), + datetimes=strptime( paste(dates,times), "%m/%d/%y %H:%M:%S") +) + +print(temp) + +write.xport( DATETIME=temp, filename="datetime.xpt") +temp2 <- read.xport(file="datetime.xpt") + +print(temp2) + + +identical(temp, temp2) Added: trunk/SASxport/tests/xxx.R =================================================================== --- trunk/SASxport/tests/xxx.R (rev 0) +++ trunk/SASxport/tests/xxx.R 2007-08-03 00:35:07 UTC (rev 1109) @@ -0,0 +1,54 @@ +library(SASxport) + +## manually create a data set +abc <- data.frame( x=c(1, 2, NA, NA ), y=c('a', 'B', NA, '*' ) ) + +## add a format specifier (not used by R) +attr(abc$x, 'format') <- 'date7.' + +## add a variable label (not used by R) +attr(abc$y, 'label') <- 'character variable' + +# create a SAS XPORT file from our local data fram +write.xport(abc, + filename="xxx2.xpt", + cDate=strptime("28JUL07:21:08:06 ", format="%d%b%y:%H:%M:%S"), + osType="SunOS", + sasVer="9.1" + ) + +# read the original SAS data file +abc.SAS <- read.xport("xxx.xpt") + +## read.xport currently doesn't store the format and label attributes... +attr(abc.SAS$X, 'format') <- 'date7.' +attr(abc.SAS$Y, 'label') <- 'character variable' + +# create a SAS XPORT file from the SAS data +write.xport(abc=abc.SAS, + filename="xxx3.xpt", + cDate=strptime("28JUL07:21:08:06 ", format="%d%b%y:%H:%M:%S"), + osType="SunOS", + sasVer="9.1" + ) + + + + +## Load both files back in as raw data +a.1 <- readBin( con="xxx.xpt", what=raw(), n=1e5 ) +a.2 <- readBin( con="xxx2.xpt", what=raw(), n=1e5 ) +a.3 <- readBin( con="xxx3.xpt", what=raw(), n=1e5 ) + +## R doesn't have multiple NA types, while SAS does. The original +## file contains a SAS '.A' missing value, while what we've created +## contains an ordinary '.' missing value, so mash this one byte to +## avoid a comparison error for this know limitation. + +a.1[1089] <- as.raw("0x2e") + +## Test that the files are otherwise identical +assert( all(a.1 == a.2) ) +assert( all(a.1 == a.3) ) + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |