r-gregmisc-users Mailing List for R gregmisc package (Page 34)
Brought to you by:
warnes
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
(12) |
Apr
(5) |
May
(3) |
Jun
(5) |
Jul
(2) |
Aug
(5) |
Sep
(7) |
Oct
(15) |
Nov
(34) |
Dec
(3) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(3) |
Feb
(16) |
Mar
(28) |
Apr
(5) |
May
|
Jun
(5) |
Jul
(9) |
Aug
(50) |
Sep
(29) |
Oct
(9) |
Nov
(25) |
Dec
(7) |
2008 |
Jan
(6) |
Feb
(4) |
Mar
(5) |
Apr
(8) |
May
(26) |
Jun
(11) |
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
(9) |
2009 |
Jan
|
Feb
(1) |
Mar
|
Apr
(2) |
May
(26) |
Jun
|
Jul
(10) |
Aug
(6) |
Sep
|
Oct
(7) |
Nov
(3) |
Dec
(2) |
2010 |
Jan
(45) |
Feb
(11) |
Mar
|
Apr
(1) |
May
(8) |
Jun
(7) |
Jul
(3) |
Aug
(1) |
Sep
|
Oct
(1) |
Nov
(9) |
Dec
(1) |
2011 |
Jan
(2) |
Feb
|
Mar
|
Apr
(3) |
May
(1) |
Jun
|
Jul
|
Aug
(14) |
Sep
(29) |
Oct
(3) |
Nov
|
Dec
(3) |
2012 |
Jan
|
Feb
|
Mar
|
Apr
(7) |
May
(6) |
Jun
(59) |
Jul
|
Aug
(8) |
Sep
(21) |
Oct
|
Nov
|
Dec
|
2013 |
Jan
(1) |
Feb
|
Mar
(10) |
Apr
|
May
(18) |
Jun
(25) |
Jul
(18) |
Aug
(1) |
Sep
(6) |
Oct
(28) |
Nov
(4) |
Dec
(13) |
2014 |
Jan
(7) |
Feb
(5) |
Mar
(4) |
Apr
(36) |
May
(3) |
Jun
(7) |
Jul
(46) |
Aug
(14) |
Sep
(12) |
Oct
(2) |
Nov
|
Dec
(12) |
2015 |
Jan
(4) |
Feb
|
Mar
|
Apr
(80) |
May
(36) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <wa...@us...> - 2007-09-07 16:32:38
|
Revision: 1166 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1166&view=rev Author: warnes Date: 2007-09-07 09:32:31 -0700 (Fri, 07 Sep 2007) Log Message: ----------- Change argument name in write.xport from 'filename' to 'file' to match read.xport Modified Paths: -------------- trunk/SASxport/tests/Alfalfa_Test.Rout.save trunk/SASxport/tests/cars.Rout.save trunk/SASxport/tests/testDates.Rout.save trunk/SASxport/tests/xxx.Rout.save Modified: trunk/SASxport/tests/Alfalfa_Test.Rout.save =================================================================== --- trunk/SASxport/tests/Alfalfa_Test.Rout.save 2007-09-07 16:25:56 UTC (rev 1165) +++ trunk/SASxport/tests/Alfalfa_Test.Rout.save 2007-09-07 16:32:31 UTC (rev 1166) @@ -1,5 +1,5 @@ -R version 2.6.0 Under development (unstable) (2007-08-04 r42421) +R version 2.5.1 (2007-06-27) Copyright (C) 2007 The R Foundation for Statistical Computing ISBN 3-900051-07-0 @@ -34,7 +34,7 @@ > > ## Write it out again, pretending to be the same OS, SAS version, and creation date > write.xport(SPEC, -+ filename="Alfalfa2.xpt", ++ file="Alfalfa2.xpt", + cDate=strptime("10DEC99:15:56:30", format="%d%b%y:%H:%M:%S"), + osType="OSF1", + sasVer="7.00" Modified: trunk/SASxport/tests/cars.Rout.save =================================================================== --- trunk/SASxport/tests/cars.Rout.save 2007-09-07 16:25:56 UTC (rev 1165) +++ trunk/SASxport/tests/cars.Rout.save 2007-09-07 16:32:31 UTC (rev 1166) @@ -1,5 +1,5 @@ -R version 2.6.0 Under development (unstable) (2007-08-04 r42421) +R version 2.5.1 (2007-06-27) Copyright (C) 2007 The R Foundation for Statistical Computing ISBN 3-900051-07-0 @@ -50,7 +50,7 @@ Datsun:4 > > write.xport(cars, -+ filename="cars2.xpt", ++ file="cars2.xpt", + cDate=strptime("28JUL07: 20:59:49", format="%d%b%y:%H:%M:%S"), + osType="SunOS", + sasVer="9.1" Modified: trunk/SASxport/tests/testDates.Rout.save =================================================================== --- trunk/SASxport/tests/testDates.Rout.save 2007-09-07 16:25:56 UTC (rev 1165) +++ trunk/SASxport/tests/testDates.Rout.save 2007-09-07 16:32:31 UTC (rev 1166) @@ -1,5 +1,5 @@ -R version 2.6.0 Under development (unstable) (2007-08-04 r42421) +R version 2.5.1 (2007-06-27) Copyright (C) 2007 The R Foundation for Statistical Computing ISBN 3-900051-07-0 @@ -46,7 +46,7 @@ 4 4 d 1992-02-28 1992-02-28 18:21:03 5 5 e 1992-02-01 1992-02-01 16:56:26 > -> write.xport( DATETIME=temp, filename="datetime.xpt") +> write.xport( DATETIME=temp, file="datetime.xpt") > temp2 <- read.xport(file="datetime.xpt", names.tolower=FALSE) > > print(temp2) Modified: trunk/SASxport/tests/xxx.Rout.save =================================================================== --- trunk/SASxport/tests/xxx.Rout.save 2007-09-07 16:25:56 UTC (rev 1165) +++ trunk/SASxport/tests/xxx.Rout.save 2007-09-07 16:32:31 UTC (rev 1166) @@ -1,5 +1,5 @@ -R version 2.6.0 Under development (unstable) (2007-08-04 r42421) +R version 2.5.1 (2007-06-27) Copyright (C) 2007 The R Foundation for Statistical Computing ISBN 3-900051-07-0 @@ -37,7 +37,7 @@ > > # create a SAS XPORT file from our local data fram > write.xport(abc, -+ filename="xxx2.xpt", ++ file="xxx2.xpt", + cDate=strptime("28JUL07:21:08:06 ", format="%d%b%y:%H:%M:%S"), + osType="SunOS", + sasVer="9.1" @@ -51,7 +51,7 @@ > > # create a SAS XPORT file from the SAS data > write.xport(abc=abc.SAS, -+ filename="xxx3.xpt", ++ file="xxx3.xpt", + cDate=strptime("28JUL07:21:08:06 ", format="%d%b%y:%H:%M:%S"), + osType="SunOS", + sasVer="9.1" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2007-09-07 16:25:57
|
Revision: 1165 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1165&view=rev Author: warnes Date: 2007-09-07 09:25:56 -0700 (Fri, 07 Sep 2007) Log Message: ----------- Change argument name in write.xport from 'filename' to 'file' to match read.xport Modified Paths: -------------- trunk/SASxport/man/write.xport.Rd Modified: trunk/SASxport/man/write.xport.Rd =================================================================== --- trunk/SASxport/man/write.xport.Rd 2007-09-07 16:23:10 UTC (rev 1164) +++ trunk/SASxport/man/write.xport.Rd 2007-09-07 16:25:56 UTC (rev 1165) @@ -95,7 +95,7 @@ abc <- temp # create a SAS XPORT file -write.xport( abc, filename="xxx.dat" ) +write.xport( abc, file="xxx.dat" ) # list the contents of the file lookup.xport("xxx.dat") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2007-09-07 16:23:10
|
Revision: 1164 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1164&view=rev Author: warnes Date: 2007-09-07 09:23:10 -0700 (Fri, 07 Sep 2007) Log Message: ----------- Change argument name in write.xport from 'filename' to 'file' to match read.xport Modified Paths: -------------- trunk/SASxport/R/write.xport.R trunk/SASxport/man/read.xport.Rd trunk/SASxport/man/write.xport.Rd trunk/SASxport/tests/Alfalfa_Test.R trunk/SASxport/tests/cars.R trunk/SASxport/tests/testDates.R trunk/SASxport/tests/xxx.R Modified: trunk/SASxport/R/write.xport.R =================================================================== --- trunk/SASxport/R/write.xport.R 2007-09-07 16:21:08 UTC (rev 1163) +++ trunk/SASxport/R/write.xport.R 2007-09-07 16:23:10 UTC (rev 1164) @@ -1,5 +1,5 @@ write.xport <- function( ... , - filename="", + file="", verbose=FALSE, sasVer="7.00", osType, @@ -26,7 +26,7 @@ ## capture names of data frame, but don't clobber explicitly provided names mc <- match.call() - mc$filename <- NULL + mc$file <- NULL mc$verbose <- NULL mc$sasVer <- NULL mc$osType <- NULL @@ -41,11 +41,11 @@ names(dfList) <- dfNames scat("opening file ...") - if (is.character(filename)) - if (filename == "") + if (is.character(file)) + if (file == "") file <- stdout() else { - file <- file(description=filename, open="wb") + file <- file(description=file, open="wb") on.exit(close(file)) } scat("Done") @@ -175,8 +175,8 @@ } scat("Closing file ...") - if (is.character(filename)) - if (filename != "") + if (is.character(file)) + if (file != "") { close(file) on.exit() Modified: trunk/SASxport/man/read.xport.Rd =================================================================== --- trunk/SASxport/man/read.xport.Rd 2007-09-07 16:21:08 UTC (rev 1163) +++ trunk/SASxport/man/read.xport.Rd 2007-09-07 16:23:10 UTC (rev 1164) @@ -71,8 +71,6 @@ \details{ \itemize{ - \item variable names are converted to lower case - \item SAS date, time, and date/time variables are converted respectively to \code{Date}, POSIX, or \code{chron} objects Modified: trunk/SASxport/man/write.xport.Rd =================================================================== --- trunk/SASxport/man/write.xport.Rd 2007-09-07 16:21:08 UTC (rev 1163) +++ trunk/SASxport/man/write.xport.Rd 2007-09-07 16:23:10 UTC (rev 1164) @@ -6,12 +6,12 @@ library file. } \usage{ -write.xport(..., filename = "", verbose = FALSE, sasVer = "7.00", +write.xport(..., file = "", verbose = FALSE, sasVer = "7.00", osType, cDate = Sys.time()) } \arguments{ \item{\dots}{One or more data frames to be stored} - \item{filename}{Filename or connection object. Use "" to view the raw data} + \item{file}{File name or connection object. Use "" to view the raw data} \item{verbose}{Logical flag controlling whether status is reported during processing} \item{sasVer}{SAS version string} Modified: trunk/SASxport/tests/Alfalfa_Test.R =================================================================== --- trunk/SASxport/tests/Alfalfa_Test.R 2007-09-07 16:21:08 UTC (rev 1163) +++ trunk/SASxport/tests/Alfalfa_Test.R 2007-09-07 16:23:10 UTC (rev 1164) @@ -8,7 +8,7 @@ ## Write it out again, pretending to be the same OS, SAS version, and creation date write.xport(SPEC, - filename="Alfalfa2.xpt", + file="Alfalfa2.xpt", cDate=strptime("10DEC99:15:56:30", format="%d%b%y:%H:%M:%S"), osType="OSF1", sasVer="7.00" Modified: trunk/SASxport/tests/cars.R =================================================================== --- trunk/SASxport/tests/cars.R 2007-09-07 16:21:08 UTC (rev 1163) +++ trunk/SASxport/tests/cars.R 2007-09-07 16:23:10 UTC (rev 1164) @@ -10,7 +10,7 @@ summary(cars) write.xport(cars, - filename="cars2.xpt", + file="cars2.xpt", cDate=strptime("28JUL07: 20:59:49", format="%d%b%y:%H:%M:%S"), osType="SunOS", sasVer="9.1" Modified: trunk/SASxport/tests/testDates.R =================================================================== --- trunk/SASxport/tests/testDates.R 2007-09-07 16:21:08 UTC (rev 1163) +++ trunk/SASxport/tests/testDates.R 2007-09-07 16:23:10 UTC (rev 1164) @@ -14,7 +14,7 @@ print(temp) -write.xport( DATETIME=temp, filename="datetime.xpt") +write.xport( DATETIME=temp, file="datetime.xpt") temp2 <- read.xport(file="datetime.xpt", names.tolower=FALSE) print(temp2) Modified: trunk/SASxport/tests/xxx.R =================================================================== --- trunk/SASxport/tests/xxx.R 2007-09-07 16:21:08 UTC (rev 1163) +++ trunk/SASxport/tests/xxx.R 2007-09-07 16:23:10 UTC (rev 1164) @@ -11,7 +11,7 @@ # create a SAS XPORT file from our local data fram write.xport(abc, - filename="xxx2.xpt", + file="xxx2.xpt", cDate=strptime("28JUL07:21:08:06 ", format="%d%b%y:%H:%M:%S"), osType="SunOS", sasVer="9.1" @@ -25,7 +25,7 @@ # create a SAS XPORT file from the SAS data write.xport(abc=abc.SAS, - filename="xxx3.xpt", + file="xxx3.xpt", cDate=strptime("28JUL07:21:08:06 ", format="%d%b%y:%H:%M:%S"), osType="SunOS", sasVer="9.1" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2007-09-07 16:21:11
|
Revision: 1163 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1163&view=rev Author: warnes Date: 2007-09-07 09:21:08 -0700 (Fri, 07 Sep 2007) Log Message: ----------- Fix typo Modified Paths: -------------- trunk/SASxport/DESCRIPTION Modified: trunk/SASxport/DESCRIPTION =================================================================== --- trunk/SASxport/DESCRIPTION 2007-09-06 14:06:13 UTC (rev 1162) +++ trunk/SASxport/DESCRIPTION 2007-09-07 16:21:08 UTC (rev 1163) @@ -29,7 +29,7 @@ <f.h...@va...>, and are utilized and redistributed under the terms of the GNU General Public License, version 2.0 or later. -- - This creation of this package was funded by Metrum Institute + The creation of this package was funded by Metrum Institute <http://metruminstitute.org>. Maintainer: Gregory R. Warnes <gr...@ra...> License: GPL 2.0 or later This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2007-09-06 14:06:15
|
Revision: 1162 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1162&view=rev Author: ggorjan Date: 2007-09-06 07:06:13 -0700 (Thu, 06 Sep 2007) Log Message: ----------- keyword Modified Paths: -------------- trunk/gdata/man/gdata-package.Rd Modified: trunk/gdata/man/gdata-package.Rd =================================================================== --- trunk/gdata/man/gdata-package.Rd 2007-08-29 02:24:31 UTC (rev 1161) +++ trunk/gdata/man/gdata-package.Rd 2007-09-06 14:06:13 UTC (rev 1162) @@ -31,4 +31,4 @@ } -\keyword{misc} \ No newline at end of file +\keyword{package} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2007-08-29 02:25:14
|
Revision: 1161 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1161&view=rev Author: warnes Date: 2007-08-28 19:24:31 -0700 (Tue, 28 Aug 2007) Log Message: ----------- Update Version to 1.0, depend on current version of foreign Modified Paths: -------------- trunk/SASxport/DESCRIPTION Modified: trunk/SASxport/DESCRIPTION =================================================================== --- trunk/SASxport/DESCRIPTION 2007-08-22 19:21:14 UTC (rev 1160) +++ trunk/SASxport/DESCRIPTION 2007-08-29 02:24:31 UTC (rev 1161) @@ -1,8 +1,8 @@ Package: SASxport Type: Package Title: Read and Write SAS XPORT Files -Version: 0.99.3 -Date: 2007-08-15 +Version: 1.0.0 +Date: 2007-08-28 Description: This package provides functions for reading, listing the contents of, and writing SAS xport format files. The functions support reading and writing of either @@ -33,6 +33,6 @@ <http://metruminstitute.org>. Maintainer: Gregory R. Warnes <gr...@ra...> License: GPL 2.0 or later -Imports: foreign, chron +Imports: foreign (>= 0.8-20), chron Enhances: foreign URL: http://random-technologies-llc.com, http://metruminstitute.org This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2007-08-22 19:21:15
|
Revision: 1160 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1160&view=rev Author: warnes Date: 2007-08-22 12:21:14 -0700 (Wed, 22 Aug 2007) Log Message: ----------- Update ChangeLog and NEWS files Added Paths: ----------- trunk/SASxport/ChangeLog trunk/SASxport/NEWS trunk/SASxport/inst/ChangeLog trunk/SASxport/inst/NEWS Added: trunk/SASxport/ChangeLog =================================================================== --- trunk/SASxport/ChangeLog (rev 0) +++ trunk/SASxport/ChangeLog 2007-08-22 19:21:14 UTC (rev 1160) @@ -0,0 +1 @@ +link inst/ChangeLog \ No newline at end of file Property changes on: trunk/SASxport/ChangeLog ___________________________________________________________________ Name: svn:special + * Added: trunk/SASxport/NEWS =================================================================== --- trunk/SASxport/NEWS (rev 0) +++ trunk/SASxport/NEWS 2007-08-22 19:21:14 UTC (rev 1160) @@ -0,0 +1 @@ +link inst/NEWS \ No newline at end of file Property changes on: trunk/SASxport/NEWS ___________________________________________________________________ Name: svn:special + * Added: trunk/SASxport/inst/ChangeLog =================================================================== --- trunk/SASxport/inst/ChangeLog (rev 0) +++ trunk/SASxport/inst/ChangeLog 2007-08-22 19:21:14 UTC (rev 1160) @@ -0,0 +1,222 @@ +2007-08-22 18:11 warnes + + * R/read.xport.R, man/read.xport.Rd, tests/xport.Rout.save: Modify + read.xport to preserve case of SAS names by default, as well as + updating the example code. + +2007-08-22 01:19 warnes + + * src/reverse.c: sprintf() was being used where printf() was + intended. + +2007-08-21 18:16 warnes + + * DESCRIPTION: Slight improvement to credits for BRL-CAD + +2007-08-21 18:13 warnes + + * TODO, man/lookup.xport.Rd, man/read.xport.Rd: Commit previous + updates + +2007-08-21 18:12 warnes + + * src/htond.c, src/ibm2ieee.c, src/ieee2ibm.c, src/init.c, + src/reverse.c, src/test_fields.c: Commit previous updates + +2007-08-15 07:02 warnes + + * DESCRIPTION, man/SASxport-package.Rd, src/cnxptiee.c, + src/cnxptiee.h, src/htond.c, src/init.c, src/reverse.c, + src/test_fields.c, src/writeSAS.c, src/writeSAS.h: Remove + dependency on SAS code + +2007-08-15 06:06 warnes + + * src/reverse.c: Fix reverse.c because we need to swap everything + to match Big-Endian, rather than Little-Endian. Also, dont' call + the macro. + +2007-08-15 06:04 warnes + + * src/reverse.c: Restore reverse.c + +2007-08-15 03:17 warnes + + * DESCRIPTION: Minor reformatting + +2007-08-15 03:14 warnes + + * DESCRIPTION, inst/doc/SAS_TS140.txt, inst/doc/index.html, + inst/doc/r2xpt.doc, man/SASxport-package.Rd, man/lookup.xport.Rd, + man/read.xport.Rd, man/toSAS.Rd, man/units.Rd, + man/write.xport.Rd: Make corrections for typos noted by Metrum + folks + +2007-08-12 03:22 warnes + + * DESCRIPTION, man/lookup.xport.Rd, src/cnxptiee.h, + src/test_fields.c, src/writeSAS.h: More updates + +2007-08-12 03:13 warnes + + * src/B8.h, src/IEEEtoIBM.c, src/MASKS.h, src/main.c, + src/reverse.c: Remove new stuff... use SAS's code instead + +2007-08-12 03:12 warnes + + * src/B8.h, src/IEEEtoIBM.c, src/MASKS.h, src/cnxptiee.h, + src/main.c, src/reverse.c, src/test_fields.c, src/writeSAS.h: 1st + attempt at rewriting cnxptiee.[ch] + +2007-08-11 23:48 warnes + + * R/read.xport.R: Explicitly check file header + +2007-08-11 00:03 warnes + + * DESCRIPTION, man/SASxport-package.Rd: Improve package description + +2007-08-09 23:29 warnes + + * DESCRIPTION, NAMESPACE, TODO, man/lookup.xport.Rd, + man/read.xport.Rd, man/units.Rd: More changes, esp to + lookup.xport() and friends + +2007-08-09 23:28 warnes + + * tests/Alfalfa_Test.Rout.save, tests/cars.Rout.save, + tests/xport.Rout.save: More changes, esp to lookup.xport() and + friends + +2007-08-09 23:28 warnes + + * R/AFirst.lib.s, R/all.is.numeric.R, R/in.opererator.R, + R/lookup.xport.R, R/read.xport.R, R/write.xport.R: More changes, + esp to lookup.xport() and friends + +2007-08-09 19:02 warnes + + * src/swap_bytes.h: Remove unused swap_bytes.h + +2007-08-09 19:02 warnes + + * man/SASxport-package.Rd: Add package description page + +2007-08-09 16:54 warnes + + * R/importConvertDateTime.R, R/makeNames.R, R/read.xport.R, + R/testDateTime.R: Add comment header indicating the source of + code from Hmisc + +2007-08-09 16:53 warnes + + * tests/testDates.Rout.save, tests/test_fields.Rout.save, + tests/xport.Rout.save, tests/xxx.Rout.save: Update saved output + of test scripts + +2007-08-08 18:54 warnes + + * DESCRIPTION, NAMESPACE: Updates + +2007-08-08 18:54 warnes + + * tests/Alfalfa_Test.R, tests/Alfalfa_Test.Rout.save, tests/cars.R, + tests/cars.Rout.save, tests/datetime.xpt, tests/testDates.R, + tests/test_fields.R, tests/test_fields.Rout.save, tests/xport.R, + tests/xxx.R, tests/xxx.Rout.save: Updates + +2007-08-08 18:54 warnes + + * src/SASxport.c, src/SASxport.h, src/foreign.h, src/init.c: + Updates + +2007-08-08 18:53 warnes + + * R/AFirst.lib.s, R/formats.R, R/iformat.R, + R/importConvertDateTime.R, R/label.R, R/lookup.xport.R, + R/makeNames.R, R/read.xport.R, R/testDateTime.R, R/units.R, + R/xport.R: Updates + +2007-08-08 18:53 warnes + + * man/assert.Rd, man/read.xport.Rd, man/units.Rd: Updates. + +2007-08-03 04:44 warnes + + * DESCRIPTION, NAMESPACE, R/scat.R, R/xport.R, R/zzz.R, + man/lookup.xport.Rd, man/read.xport.Rd, src/SASxport.c, + src/SASxport.h, src/cnxptiee.c, src/cnxptiee.h, src/foreign.h, + src/init.c, src/swap_bytes.h, src/test_fields.c, src/writeSAS.c, + src/writeSAS.h, tests/Alfalfa_Test.Rout.save, + tests/cars.Rout.save, tests/datetime.xpt, tests/test.xpt, + tests/testDates.Rout.save, tests/test_fields.Rout.save, + tests/xport.R, tests/xport.Rout.save, tests/xxx.Rout.save: Add + code from package foreign and gtools to make SASxport stand alone + +2007-08-03 01:46 warnes + + * R/.Rhistory: Remove stray .Rhistory file + +2007-08-03 01:45 warnes + + * DESCRIPTION: Acknowledge MetrumI support + +2007-08-03 01:45 warnes + + * NAMESPACE: Add "assert" function + +2007-08-03 01:44 warnes + + * R/assert.R, man/assert.Rd: Add "assert" function to avoid + dependenct on gtools. + +2007-08-03 01:29 warnes + + * man/toSAS.Rd, src/cnxptiee.c, src/writeSAS.c: Correct some typos. + +2007-08-03 00:40 warnes + + * DESCRIPTION: Drop version number to 0.99 until testing + integration and is complete + +2007-08-03 00:39 warnes + + * tests/test_fields.R: Add R test file to run c-level tests + +2007-08-03 00:36 warnes + + * src/SASxport.so: Remove .so from svn + +2007-08-03 00:35 warnes + + * NAMESPACE, R/fromSASDate.R, R/parseFormat.R, R/toSAS.R, + R/write.xport.R, R/xport.character.R, R/xport.file.header.R, + R/xport.member.header.R, R/xport.namestr.R, man/toSAS.Rd, + src/SASxport.so, src/writeSAS.c: More modifications. Should now + work for most R data types + +2007-08-03 00:35 warnes + + * tests/cars.R, tests/datetime.xpt, tests/testDates.R, tests/xxx.R: + Add more tests + +2007-07-29 01:15 warnes + + * tests/Alfalfa2.xpt, tests/cars.sas, tests/cars.xpt, + tests/xxx.sas, tests/xxx.xpt: Add SAS code to create xport data + files for testing + +2007-07-28 08:47 warnes + + * ., DESCRIPTION, NAMESPACE, R, R/.Rhistory, R/blanks.R, + R/rawToDisplay.R, R/write.xport.R, R/xport.NA.R, + R/xport.character.R, R/xport.dateFMT.R, R/xport.file.header.R, + R/xport.fill.R, R/xport.member.header.R, R/xport.namestr.R, + R/xport.namestr.header.R, R/xport.numeric.R, + R/xport.obs.header.R, R/zzz.R, inst, inst/doc, + inst/doc/SAS_TS140.txt, inst/doc/index.html, inst/doc/r2xpt.doc, + man, man/write.xport.Rd, src, src/SASxport.so, src/cnxptiee.c, + src/cnxptiee.h, src/test_fields.c, src/writeSAS.c, + src/writeSAS.h, tests, tests/Alfalfa.xpt, tests/Alfalfa2.xpt, + tests/Alfalfa_Test.R: Add SVNxport package + Added: trunk/SASxport/inst/NEWS =================================================================== --- trunk/SASxport/inst/NEWS (rev 0) +++ trunk/SASxport/inst/NEWS 2007-08-22 19:21:14 UTC (rev 1160) @@ -0,0 +1,40 @@ +Beta 3 - 2007-08-10 +------------------- + +New features: + +- read.xport's names.tolower argument now defaults to FALSE so that + variable (and data set) names are now left as uppercase. + +- Improved crediting of BRL-CAD source code + +Bug fixes: + +- Correct call to sprintf where printf was intended in src/ieee2ibm.c + +Other: + +- Augmented ieee2ibm code with corresponding ibm2ieee code for + completeness. + + +Beta 2 - 2007-08-10 +------------------- + +New Features: + +- Replaced IEEE to IBM translation code with GPL'ed version from BPL-CAD. + +Bug Fixes: + +- Changes to C code should correct the C99 usage errors + +- Correct documentation typos, including those reported by Tim. + + +Beta 1 - 2007-08-10 +------------------- + +Initial version of the SASxport package. + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2007-08-22 18:11:59
|
Revision: 1159 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1159&view=rev Author: warnes Date: 2007-08-22 11:11:44 -0700 (Wed, 22 Aug 2007) Log Message: ----------- Modify read.xport to preserve case of SAS names by default, as well as updating the example code. Modified Paths: -------------- trunk/SASxport/R/read.xport.R trunk/SASxport/man/read.xport.Rd trunk/SASxport/tests/xport.Rout.save Modified: trunk/SASxport/R/read.xport.R =================================================================== --- trunk/SASxport/R/read.xport.R 2007-08-22 01:19:46 UTC (rev 1158) +++ trunk/SASxport/R/read.xport.R 2007-08-22 18:11:44 UTC (rev 1159) @@ -8,7 +8,7 @@ force.integer=TRUE, formats=NULL, name.chars=NULL, - names.tolower=TRUE, + names.tolower=FALSE, keep=NULL, drop=NULL, as.is=0.95, # Prevent factor conversion if 95% or more unique Modified: trunk/SASxport/man/read.xport.Rd =================================================================== --- trunk/SASxport/man/read.xport.Rd 2007-08-22 01:19:46 UTC (rev 1158) +++ trunk/SASxport/man/read.xport.Rd 2007-08-22 18:11:44 UTC (rev 1159) @@ -9,7 +9,7 @@ force.integer=TRUE, formats=NULL, name.chars=NULL, - names.tolower=TRUE, + names.tolower=FALSE, keep=NULL, drop=NULL, as.is=0.95, @@ -107,7 +107,7 @@ \code{\link[Hmisc]{describe}} } \examples{ -\dontrun{ + # ------- # SAS code to generate test dataset: # ------- @@ -149,44 +149,31 @@ # ------ # Read this dataset from a local file: +\dontrun{ w <- read.xport('test2.xpt') - -\dontshow{ -library(Hmisc) -w2 <- sasxport.get('test2.xpt') -SASxport:::assert(identical(w,w2)) } -\dontrun{ + # Or read a copy of test2.xpt available on the web: url <- 'http://biostat.mc.vanderbilt.edu/cgi-bin/viewvc.cgi/*checkout*/Hmisc/trunk/tests/test2.xpt' w <- read.xport(url) -\dontshow{ ## For testing only -SASxport:::assert(identical(w2,w)) -} -} - \dontrun{ ## The Hmisc library provides many useful functions for interacting with ## data imported from SAS via read.xport() library(Hmisc) describe(w$test) # see labels, format names for dataset test +lapply(w, describe)# see descriptive stats in more detaiil for each variable -lapply(w, describe)# see descriptive stats for both datasets - contents(w$test) # another way to see variable attributes -lapply(w, contents)# show contents of both datasets +lapply(w, contents)# show contents of individual items in more detail options(digits=7) # compare the following matrix with PROC MEANS output t(sapply(w$z, function(x) c(Mean=mean(x),SD=sqrt(var(x)),Min=min(x),Max=max(x)))) - } } - -} \keyword{interface} \keyword{manip} Modified: trunk/SASxport/tests/xport.Rout.save =================================================================== --- trunk/SASxport/tests/xport.Rout.save 2007-08-22 01:19:46 UTC (rev 1158) +++ trunk/SASxport/tests/xport.Rout.save 2007-08-22 18:11:44 UTC (rev 1159) @@ -1,5 +1,5 @@ -R version 2.6.0 Under development (unstable) (2007-08-04 r42421) +R version 2.5.1 (2007-06-27) Copyright (C) 2007 The R Foundation for Statistical Computing ISBN 3-900051-07-0 @@ -45,14 +45,14 @@ > Alfalfa <- read.xport("Alfalfa.xpt") > > summary(Alfalfa) - pop sample rep seedwt harv1 + POP SAMPLE REP SEEDWT HARV1 MAX:20 Min. :0.0 Min. :1.00 Min. :35.00 Min. :120.6 min:20 1st Qu.:2.0 1st Qu.:1.75 1st Qu.:47.75 1st Qu.:148.3 Median :4.5 Median :2.50 Median :59.00 Median :165.8 Mean :4.5 Mean :2.50 Mean :56.08 Mean :163.0 3rd Qu.:7.0 3rd Qu.:3.25 3rd Qu.:62.25 3rd Qu.:176.4 Max. :9.0 Max. :4.00 Max. :75.00 Max. :193.4 - harv2 + HARV2 Min. :129.1 1st Qu.:150.6 Median :163.2 @@ -75,7 +75,7 @@ > testdata <- read.xport("test.xpt") > summary(testdata) - i k + I K Min. :1.00 Min. :1 1st Qu.:1.75 1st Qu.:1 Median :2.50 Median :2 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2007-08-22 01:19:50
|
Revision: 1158 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1158&view=rev Author: warnes Date: 2007-08-21 18:19:46 -0700 (Tue, 21 Aug 2007) Log Message: ----------- sprintf() was being used where printf() was intended. Modified Paths: -------------- trunk/SASxport/src/reverse.c Modified: trunk/SASxport/src/reverse.c =================================================================== --- trunk/SASxport/src/reverse.c 2007-08-21 18:16:47 UTC (rev 1157) +++ trunk/SASxport/src/reverse.c 2007-08-22 01:19:46 UTC (rev 1158) @@ -18,7 +18,7 @@ if( (short) *endianTest != 1 ) { /* The native byte order is big endian, so do nothing */ - sprintf("Big Endian Machine!\n"); + printf("Big Endian Machine!\n"); return; } #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2007-08-21 18:16:48
|
Revision: 1157 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1157&view=rev Author: warnes Date: 2007-08-21 11:16:47 -0700 (Tue, 21 Aug 2007) Log Message: ----------- Slight improvement to credits for BRL-CAD Modified Paths: -------------- trunk/SASxport/DESCRIPTION Modified: trunk/SASxport/DESCRIPTION =================================================================== --- trunk/SASxport/DESCRIPTION 2007-08-21 18:13:07 UTC (rev 1156) +++ trunk/SASxport/DESCRIPTION 2007-08-21 18:16:47 UTC (rev 1157) @@ -1,7 +1,7 @@ Package: SASxport Type: Package Title: Read and Write SAS XPORT Files -Version: 0.99.2 +Version: 0.99.3 Date: 2007-08-15 Description: This package provides functions for reading, listing the contents of, and writing SAS xport format files. @@ -16,7 +16,8 @@ <http://random-technologies-llc.com>, and are provided under the terms of the GNU General Public License, version 2.0 or later. -- - The file 'htond.c' was written by Michael John Muuss and is + 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. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2007-08-21 18:13:15
|
Revision: 1156 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1156&view=rev Author: warnes Date: 2007-08-21 11:13:07 -0700 (Tue, 21 Aug 2007) Log Message: ----------- Commit previous updates Modified Paths: -------------- trunk/SASxport/TODO trunk/SASxport/man/lookup.xport.Rd trunk/SASxport/man/read.xport.Rd Modified: trunk/SASxport/TODO =================================================================== --- trunk/SASxport/TODO 2007-08-21 18:12:39 UTC (rev 1155) +++ trunk/SASxport/TODO 2007-08-21 18:13:07 UTC (rev 1156) @@ -1,17 +1,6 @@ -- Write replacements for SAS's REVERSE function, which corrects for - differences in endianness, and cnxptieee function, which is used to - convert from the IBM floating point representation to the IEEE - representation. - - Write test routines for very large files, particulary very large files with columns contiaining almost all missing values. - Test that created files are properly read by SAS, particulary when the SAS version and OS version are set to the default values I've provided. - -- Check function for 64 bit versions of R. I suspect that there may - be variable size issues for some int fields for write.xport(). - -- - Modified: trunk/SASxport/man/lookup.xport.Rd =================================================================== --- trunk/SASxport/man/lookup.xport.Rd 2007-08-21 18:12:39 UTC (rev 1155) +++ trunk/SASxport/man/lookup.xport.Rd 2007-08-21 18:13:07 UTC (rev 1156) @@ -50,6 +50,7 @@ } ## Or read a copy of test2.xpt available on the web: +\dontrun{ url <- 'http://biostat.mc.vanderbilt.edu/cgi-bin/viewvc.cgi/*checkout*/Hmisc/trunk/tests/test2.xpt' w <- lookup.xport(url) @@ -68,7 +69,8 @@ # variable names within all data sets wS$name +} } \keyword{file} -\keyword{manip} \ No newline at end of file +\keyword{manip} Modified: trunk/SASxport/man/read.xport.Rd =================================================================== --- trunk/SASxport/man/read.xport.Rd 2007-08-21 18:12:39 UTC (rev 1155) +++ trunk/SASxport/man/read.xport.Rd 2007-08-21 18:13:07 UTC (rev 1156) @@ -157,6 +157,7 @@ SASxport:::assert(identical(w,w2)) } +\dontrun{ # Or read a copy of test2.xpt available on the web: url <- 'http://biostat.mc.vanderbilt.edu/cgi-bin/viewvc.cgi/*checkout*/Hmisc/trunk/tests/test2.xpt' w <- read.xport(url) @@ -164,6 +165,7 @@ \dontshow{ ## For testing only SASxport:::assert(identical(w2,w)) } +} \dontrun{ ## The Hmisc library provides many useful functions for interacting with This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2007-08-21 18:12:42
|
Revision: 1155 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1155&view=rev Author: warnes Date: 2007-08-21 11:12:39 -0700 (Tue, 21 Aug 2007) Log Message: ----------- Commit previous updates Modified Paths: -------------- trunk/SASxport/src/init.c trunk/SASxport/src/reverse.c trunk/SASxport/src/test_fields.c Added Paths: ----------- trunk/SASxport/src/ibm2ieee.c trunk/SASxport/src/ieee2ibm.c Removed Paths: ------------- trunk/SASxport/src/htond.c Deleted: trunk/SASxport/src/htond.c =================================================================== --- trunk/SASxport/src/htond.c 2007-08-21 15:36:28 UTC (rev 1154) +++ trunk/SASxport/src/htond.c 2007-08-21 18:12:39 UTC (rev 1155) @@ -1,148 +0,0 @@ -/* H T O N D . C - * BRL-CAD - * - * Copyright (c) 2004-2007 United States Government as represented by - * the U.S. Army Research Laboratory. - * - * Minor changes (c) 2007 Random Technologies LLC by Gregory R. Warnes - * <gr...@ra...> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this file; see the file named COPYING for more - * information. - */ - -#include "writeSAS.h" -#include <stdio.h> - -/****************************/ -/** NB: htond code ommitted */ -/****************************/ - -/**************************** - * NB: The ntohd code assumes that 'in' points to a vector BIG-ENDIAN IEEE - * double precision value of length 'count'. This extracted routine - * returns IBM/360 format double precision values in *out - ***************************/ - - -void R_ntohd(double out[], double in[], int *count) -{ - int i; - int j; - unsigned char tmp; - unsigned char *cptr; - - /* Flip byte order from little endian to big endian */ - for(i=0; i<*count; i++) - reverse( (unsigned char*) &(in[i]), sizeof(double) ); - ieee2ibm( (unsigned char *) out, (unsigned char *) in, *count ); -} - -/** - * N T O H D - * - * @brief Network to Host Doubles - */ -// Original function name: "ntohd" -void ieee2ibm(register unsigned char *out, register const unsigned char *in, int count) -{ - /* - * IBM Format. - * 7-bit exponent, base 16. - * No hidden bits in mantissa (56 bits). - */ - register int i; - for( i=count-1; i >= 0; i-- ) { - register unsigned long left, right; - register int fix, exp, signbit; - - left = (in[0]<<24) | (in[1]<<16) | (in[2]<<8) | in[3]; - right = (in[4]<<24) | (in[5]<<16) | (in[6]<<8) | in[7]; - in += 8; - - exp = ((left >> 20) & 0x7FF); - signbit = (left & 0x80000000) >> 24; - if( exp == 0 || exp == 0x7FF ) { -ibm_undef: *out++ = 0; /* IBM zero. No NAN */ - *out++ = 0; - *out++ = 0; - *out++ = 0; - *out++ = 0; - *out++ = 0; - *out++ = 0; - *out++ = 0; - continue; - } - - left = (left & 0x000FFFFF) | 0x00100000;/* replace "hidden" bit */ - - exp += 129 - 1023 -1; /* fudge, to make /4 and %4 work */ - fix = exp % 4; /* 2^4 == 16^1; get fractional exp */ - exp /= 4; /* excess 32, base 16 */ - exp += (64-32+1); /* excess 64, base 16, plus fudge */ - if( (exp & ~0xFF) != 0 ) { - //WARNING("ntohd: IBM exponent overflow"); - fprintf(stderr,"ntohd: IBM exponent overflow\n"); - goto ibm_undef; - } - - if( fix ) { - left = (left<<fix) | (right >> (32-fix)); - right <<= fix; - } - - if( signbit ) { - /* The IBM actually uses complimented mantissa - * and exponent. - */ - left ^= 0xFFFFFFFF; - right ^= 0xFFFFFFFF; - if( right & 0x80000000 ) { - /* There may be a carry */ - right += 1; - if( (right & 0x80000000) == 0 ) { - /* There WAS a carry */ - left += 1; - } - } else { - /* There will be no carry to worry about */ - right += 1; - } - left &= 0x00FFFFFF; - exp = (~exp) & 0x7F; - } - - - /* Not actually required, but for comparison purposes, - * normalize the number. Remove for production speed. - */ - while( (left & 0x00F00000) == 0 && left != 0 ) { - if( signbit && exp <= 0x41 ) break; - - left = (left << 4) | (right >> (32-4)); - right <<= 4; - if(signbit) exp--; - else exp++; - } - - *out++ = signbit | exp; - *out++ = left>>16; - *out++ = left>>8; - *out++ = left; - *out++ = right>>24; - *out++ = right>>16; - *out++ = right>>8; - *out++ = right; - } - return; -} Added: trunk/SASxport/src/ibm2ieee.c =================================================================== --- trunk/SASxport/src/ibm2ieee.c (rev 0) +++ trunk/SASxport/src/ibm2ieee.c 2007-08-21 18:12:39 UTC (rev 1155) @@ -0,0 +1,171 @@ +/* + * File: SASxport/src/ibm2ieee.c + * + * Originally from BRL-CAD file /brlcad/src/libbu/htond.c + * + * Copyright (c) 2004-2007 United States Government as represented by + * the U.S. Army Research Laboratory. + * + * * Minor changes (c) 2007 Random Technologies LLC by Gregory R. Warnes + * <gr...@ra...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ + +#include "writeSAS.h" +#include <stdio.h> + +/**************************** + * ibm2ieee + * + * Convert an array of IBM/360 format double precision values of at *in + * of length 'count' to BIG-ENDIAN IEEE double precision value at *out. + * + * This code was extracted from the "ntohd" function, original author + * Michael John Muuss + * + * Note that neither the input or output buffers need be word aligned, + * for greatest flexability in converting data, even though this + * imposes a speed penalty here. + * + ***************************/ + +#define OUT_IEEE_ZERO { \ + *out++ = 0; \ + *out++ = 0; \ + *out++ = 0; \ + *out++ = 0; \ + *out++ = 0; \ + *out++ = 0; \ + *out++ = 0; \ + *out++ = 0; \ + continue; } \ + +#define OUT_IEEE_NAN { /* Signaling NAN */ \ + *out++ = 0xFF; \ + *out++ = 0xF0; \ + *out++ = 0x0B; \ + *out++ = 0xAD; \ + *out++ = 0x0B; \ + *out++ = 0xAD; \ + *out++ = 0x0B; \ + *out++ = 0xAD; \ + continue; } \ + + +void ibm2ieee(register unsigned char *out, register const unsigned char *in, int count) +{ + /* + * IBM Format. + * 7-bit exponent, base 16. + * No hidden bits in mantissa (56 bits). + */ + register int i; + for( i=count-1; i >= 0; i-- ) { + register unsigned long left, right, signbit; + register int exp; + + left = (in[0]<<24) | (in[1]<<16) | (in[2]<<8) | in[3]; + right = (in[4]<<24) | (in[5]<<16) | (in[6]<<8) | in[7]; + in += 8; + + exp = (left>>24) & 0x7F; /* excess 64, base 16 */ + if( left == 0 && right == 0 ) + OUT_IEEE_ZERO; + + signbit = left & 0x80000000; + left &= 0x00FFFFFF; + if( signbit ) { + /* The IBM uses 2's compliment on the mantissa, + * and IEEE does not. + */ + left ^= 0xFFFFFFFF; + right ^= 0xFFFFFFFF; + if( right & 0x80000000 ) { + /* There may be a carry */ + right += 1; + if( (right & 0x80000000) == 0 ) { + /* There WAS a carry */ + left += 1; + } + } else { + /* There will be no carry to worry about */ + right += 1; + } + left &= 0x00FFFFFF; + exp = (~exp) & 0x7F; + } + exp -= (64-32+1); /* excess 32, base 16, + fudge */ + exp *= 4; /* excess 128, base 2 */ +ibm_normalized: + if( left & 0x00800000 ) { + /* fix = 0; */ + exp += 1023-129+1+ 3-0;/* fudge, slide hidden bit */ + } else if( left & 0x00400000 ) { + /* fix = 1; */ + exp += 1023-129+1+ 3-1; + left = (left<<1) | + ( (right>>(32-1)) & (0x7FFFFFFF>>(31-1)) ); + right <<= 1; + } else if( left & 0x00200000 ) { + /* fix = 2; */ + exp += 1023-129+1+ 3-2; + left = (left<<2) | + ( (right>>(32-2)) & (0x7FFFFFFF>>(31-2)) ); + right <<= 2; + } else if( left & 0x00100000 ){ + /* fix = 3; */ + exp += 1023-129+1+ 3-3; + left = (left<<3) | + ( (right>>(32-3)) & (0x7FFFFFFF>>(31-3)) ); + right <<= 3; + } else { + /* Encountered 4 consecutive 0 bits of mantissa, + * attempt to normalize, and loop. + * This case was not expected, but does happen, + * at least on the Gould. + */ + exp -= 4; + left = (left<<4) | (right>>(32-4)); + right <<= 4; + goto ibm_normalized; + } + + /* After suitable testing, this check can be deleted */ + if( (left & 0x00800000) == 0 ) { + fprintf(stderr,"ibm->ieee missing 1, left=x%x\n", left); + left = (left<<1) | (right>>31); + right <<= 1; + goto ibm_normalized; + } + + /* Having nearly VAX format, shift to IEEE, rounding. */ +# ifdef ROUNDING + right = (left<<(32-3)) | ((right+4)>>3); +# else + right = (left<<(32-3)) | (right>>3); +# endif + left = ((left & 0x007FFFFF)>>3) | signbit | (exp<<20); + + *out++ = left>>24; + *out++ = left>>16; + *out++ = left>>8; + *out++ = left; + *out++ = right>>24; + *out++ = right>>16; + *out++ = right>>8; + *out++ = right; + } + return; +} Added: trunk/SASxport/src/ieee2ibm.c =================================================================== --- trunk/SASxport/src/ieee2ibm.c (rev 0) +++ trunk/SASxport/src/ieee2ibm.c 2007-08-21 18:12:39 UTC (rev 1155) @@ -0,0 +1,135 @@ +/* + * File: SASxport/src/ibm2ieee.c + * + * Originally from BRL-CAD, file /brlcad/src/libbu/htond.c + * + * Copyright (c) 2004-2007 United States Government as represented by + * the U.S. Army Research Laboratory. + * + * Minor changes (c) 2007 Random Technologies LLC by Gregory R. Warnes + * <gr...@ra...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ + +#include "writeSAS.h" +#include <stdio.h> + +/**************************** + * ieee2ibm + * + * Convert an array of BIG-ENDIAN IEEE double precision value at *in + * of length 'count'to IBM/360 format double precision values at *out + * + * This code was extracted from the "ntohd" function, original author + * Michael John Muuss + * + * Note that neither the input or output buffers need be word aligned, + * for greatest flexability in converting data, even though this + * imposes a speed penalty here. + * + ***************************/ + +void ieee2ibm(register unsigned char *out, register const unsigned char *in, int count) +{ + /* + * IBM Format. + * 7-bit exponent, base 16. + * No hidden bits in mantissa (56 bits). + */ + register int i; + for( i=count-1; i >= 0; i-- ) { + register unsigned long left, right; + register int fix, exp, signbit; + + left = (in[0]<<24) | (in[1]<<16) | (in[2]<<8) | in[3]; + right = (in[4]<<24) | (in[5]<<16) | (in[6]<<8) | in[7]; + in += 8; + + exp = ((left >> 20) & 0x7FF); + signbit = (left & 0x80000000) >> 24; + if( exp == 0 || exp == 0x7FF ) { +ibm_undef: *out++ = 0; /* IBM zero. No NAN */ + *out++ = 0; + *out++ = 0; + *out++ = 0; + *out++ = 0; + *out++ = 0; + *out++ = 0; + *out++ = 0; + continue; + } + + left = (left & 0x000FFFFF) | 0x00100000;/* replace "hidden" bit */ + + exp += 129 - 1023 -1; /* fudge, to make /4 and %4 work */ + fix = exp % 4; /* 2^4 == 16^1; get fractional exp */ + exp /= 4; /* excess 32, base 16 */ + exp += (64-32+1); /* excess 64, base 16, plus fudge */ + if( (exp & ~0xFF) != 0 ) { + //WARNING("ntohd: IBM exponent overflow"); + fprintf(stderr,"ntohd: IBM exponent overflow\n"); + goto ibm_undef; + } + + if( fix ) { + left = (left<<fix) | (right >> (32-fix)); + right <<= fix; + } + + if( signbit ) { + /* The IBM actually uses complimented mantissa + * and exponent. + */ + left ^= 0xFFFFFFFF; + right ^= 0xFFFFFFFF; + if( right & 0x80000000 ) { + /* There may be a carry */ + right += 1; + if( (right & 0x80000000) == 0 ) { + /* There WAS a carry */ + left += 1; + } + } else { + /* There will be no carry to worry about */ + right += 1; + } + left &= 0x00FFFFFF; + exp = (~exp) & 0x7F; + } + + + /* Not actually required, but for comparison purposes, + * normalize the number. Remove for production speed. + */ + while( (left & 0x00F00000) == 0 && left != 0 ) { + if( signbit && exp <= 0x41 ) break; + + left = (left << 4) | (right >> (32-4)); + right <<= 4; + if(signbit) exp--; + else exp++; + } + + *out++ = signbit | exp; + *out++ = left>>16; + *out++ = left>>8; + *out++ = left; + *out++ = right>>24; + *out++ = right>>16; + *out++ = right>>8; + *out++ = right; + } + return; +} Modified: trunk/SASxport/src/init.c =================================================================== --- trunk/SASxport/src/init.c 2007-08-21 15:36:28 UTC (rev 1154) +++ trunk/SASxport/src/init.c 2007-08-21 18:12:39 UTC (rev 1155) @@ -1,6 +1,6 @@ /******* * - * init.c: Routines to register writeSAS.c routines with R + * init.c: Routines to register SASxport C routines with R * * Author: Gregory R. Warnes <gr...@ra...> * @@ -57,8 +57,6 @@ #define CALLDEF(name, n) {#name, (DL_FUNC) &name, n} static const R_CallMethodDef CallEntries[] = { -// CALLDEF(xport_info, 1), -// CALLDEF(xport_read, 2), CALLDEF(getRawBuffer, 0), {NULL, NULL, 0} }; Modified: trunk/SASxport/src/reverse.c =================================================================== --- trunk/SASxport/src/reverse.c 2007-08-21 15:36:28 UTC (rev 1154) +++ trunk/SASxport/src/reverse.c 2007-08-21 18:12:39 UTC (rev 1155) @@ -3,8 +3,8 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#import <assert.h> -#import <sys/types.h> +#include <assert.h> +#include <sys/types.h> /* reverse: convert current byte order to big endian */ void reverse( unsigned char *intp, size_t size) Modified: trunk/SASxport/src/test_fields.c =================================================================== --- trunk/SASxport/src/test_fields.c 2007-08-21 15:36:28 UTC (rev 1154) +++ trunk/SASxport/src/test_fields.c 2007-08-21 18:12:39 UTC (rev 1155) @@ -181,7 +181,6 @@ } - void doTest() { /* small buffer */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2007-08-21 15:36:37
|
Revision: 1154 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1154&view=rev Author: ggorjan Date: 2007-08-21 08:36:28 -0700 (Tue, 21 Aug 2007) Log Message: ----------- package help page Added Paths: ----------- trunk/gdata/man/gdata-package.Rd Added: trunk/gdata/man/gdata-package.Rd =================================================================== --- trunk/gdata/man/gdata-package.Rd (rev 0) +++ trunk/gdata/man/gdata-package.Rd 2007-08-21 15:36:28 UTC (rev 1154) @@ -0,0 +1,34 @@ + +\name{gdata-package} +\alias{gdata-package} + +\docType{package} + +\title{Various R programming tools for data manipulation} + +\description{ + +\pkg{gdata} package provides various \R programming tools for data +manipulation. + +} + +\details{ +The following are sources of information on \pkg{gdata} package: +\tabular{ll}{ + DESCRIPTION file\tab \code{library(help="gdata")}\cr + \tab \cr + This file\tab \code{package?gdata}\cr + \tab \cr + Vignette\tab \code{vignette("unknown")}\cr + \tab \code{vignette("mapLevels")}\cr + \tab \cr + Some help files\tab \code{\link{read.xls}}\cr + \tab \code{\link{write.fwf}}\cr + \tab \cr + News\tab \code{file.show(system.file("NEWS", package="gdata"))}\cr +} + +} + +\keyword{misc} \ No newline at end of file Property changes on: trunk/gdata/man/gdata-package.Rd ___________________________________________________________________ Name: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2007-08-21 15:30:46
|
Revision: 1153 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1153&view=rev Author: ggorjan Date: 2007-08-21 08:30:40 -0700 (Tue, 21 Aug 2007) Log Message: ----------- move Added Paths: ----------- trunk/gdata/NEWS trunk/gdata/inst/NEWS Added: trunk/gdata/NEWS =================================================================== --- trunk/gdata/NEWS (rev 0) +++ trunk/gdata/NEWS 2007-08-21 15:30:40 UTC (rev 1153) @@ -0,0 +1 @@ +link inst/NEWS \ No newline at end of file Property changes on: trunk/gdata/NEWS ___________________________________________________________________ Name: svn:special + * Added: trunk/gdata/inst/NEWS =================================================================== --- trunk/gdata/inst/NEWS (rev 0) +++ trunk/gdata/inst/NEWS 2007-08-21 15:30:40 UTC (rev 1153) @@ -0,0 +1,75 @@ +CHANGES IN 2.3.1 (2006-10-29) +--------------------------------------- + +- Arguments as well as their position of reorder.factor have been changed + to conform with reorder.factor method in stats package, due to collision + bug. Argument 'make.ordered' is now 'order' and old argument 'order' is + now 'new.order'! Therefore, you have to implicitly specify new.order i.e. + + reorder(trt, new.order=c("PLACEBO", "300 MG", "600 MG", "1200 MG")) + +- trim() gains ... argument. + +- Added "unknown" methods for matrices. + +- Added c() method for factors based on mapLevels() functions. + +- Added write.fwf, which writes file in *F*ixed *W*idth *F*ormat. + +CHANGES FROM 2.1.X to 2.3.0 (2006-09-19) +--------------------------------------- + +- Added mapLevels(), which produces a map with information on levels and/or + internal integer codes. Contributed by Gregor Gorjanc. + +- Extended dropLevels() to work on the factors contained in a data + frame, as well as individual factors. + +- Add unknown(), which changes given unknown value to NA and vice + versa. Contributed by Gregor Gorjanc. + +- Extended trim() to handle a variety of data types data.frames, + lists, factors, etc. Code changes contributed by Gregor Gorjanc. + +- Added resample() command that acts like sample() except that it + _always_ samples from the arguments provided, even if only a single + argument is present. This differs from sample() which behaves + differently in this case. + +- Updated my email address. + +CHANGES IN GDATA 2.1.2 +----------------------- + + - Fixed bug in interleave.R - option to covert 1-column matrices to + vector (based on Andrew Burgess's suggestion) + + - Updated Greg and Jim's email adresses + + - ll.R: Suppressed warning message in attach() call. + + - frameApply.Rd, reorder.Rd: Remove explicit loading of + gtools in examples, so that failure to import functions from + gtools gets properly caught by running the examples. + + - upperTriangle.R, man/upperTriangle.Rd: Add functions for + extracting and modifying the upper and lower trianglular components of + matrices. + + - is.what.R: Replaced the "not.using" vector with a more robust + try(get(test)) to find out whether a particular is.* function + returns a logical of length one. + +- DESCRIPTION: Added Suggests field + + - Updated the example in frameApply + + +CHANGES IN GDATA 2.0.8 +----------------------- + + - Added DESCRIPTION and removed DESCRIPTION.in + + - Updated ll.Rd documentation + + - Fixed bug in Args.R, is.what.R, ll.R This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2007-08-21 15:29:43
|
Revision: 1152 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1152&view=rev Author: ggorjan Date: 2007-08-21 08:29:39 -0700 (Tue, 21 Aug 2007) Log Message: ----------- move Removed Paths: ------------- trunk/gdata/NEWS Deleted: trunk/gdata/NEWS =================================================================== --- trunk/gdata/NEWS 2007-08-20 10:18:30 UTC (rev 1151) +++ trunk/gdata/NEWS 2007-08-21 15:29:39 UTC (rev 1152) @@ -1,75 +0,0 @@ -CHANGES IN 2.3.1 (2006-10-29) ---------------------------------------- - -- Arguments as well as their position of reorder.factor have been changed - to conform with reorder.factor method in stats package, due to collision - bug. Argument 'make.ordered' is now 'order' and old argument 'order' is - now 'new.order'! Therefore, you have to implicitly specify new.order i.e. - - reorder(trt, new.order=c("PLACEBO", "300 MG", "600 MG", "1200 MG")) - -- trim() gains ... argument. - -- Added "unknown" methods for matrices. - -- Added c() method for factors based on mapLevels() functions. - -- Added write.fwf, which writes file in *F*ixed *W*idth *F*ormat. - -CHANGES FROM 2.1.X to 2.3.0 (2006-09-19) ---------------------------------------- - -- Added mapLevels(), which produces a map with information on levels and/or - internal integer codes. Contributed by Gregor Gorjanc. - -- Extended dropLevels() to work on the factors contained in a data - frame, as well as individual factors. - -- Add unknown(), which changes given unknown value to NA and vice - versa. Contributed by Gregor Gorjanc. - -- Extended trim() to handle a variety of data types data.frames, - lists, factors, etc. Code changes contributed by Gregor Gorjanc. - -- Added resample() command that acts like sample() except that it - _always_ samples from the arguments provided, even if only a single - argument is present. This differs from sample() which behaves - differently in this case. - -- Updated my email address. - -CHANGES IN GDATA 2.1.2 ------------------------ - - - Fixed bug in interleave.R - option to covert 1-column matrices to - vector (based on Andrew Burgess's suggestion) - - - Updated Greg and Jim's email adresses - - - ll.R: Suppressed warning message in attach() call. - - - frameApply.Rd, reorder.Rd: Remove explicit loading of - gtools in examples, so that failure to import functions from - gtools gets properly caught by running the examples. - - - upperTriangle.R, man/upperTriangle.Rd: Add functions for - extracting and modifying the upper and lower trianglular components of - matrices. - - - is.what.R: Replaced the "not.using" vector with a more robust - try(get(test)) to find out whether a particular is.* function - returns a logical of length one. - -- DESCRIPTION: Added Suggests field - - - Updated the example in frameApply - - -CHANGES IN GDATA 2.0.8 ------------------------ - - - Added DESCRIPTION and removed DESCRIPTION.in - - - Updated ll.Rd documentation - - - Fixed bug in Args.R, is.what.R, ll.R This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2007-08-20 10:18:34
|
Revision: 1151 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1151&view=rev Author: ggorjan Date: 2007-08-20 03:18:30 -0700 (Mon, 20 Aug 2007) Log Message: ----------- clean Removed Paths: ------------- trunk/gdata/inst/doc/mapLevels.tex Deleted: trunk/gdata/inst/doc/mapLevels.tex =================================================================== --- trunk/gdata/inst/doc/mapLevels.tex 2007-08-20 10:17:37 UTC (rev 1150) +++ trunk/gdata/inst/doc/mapLevels.tex 2007-08-20 10:18:30 UTC (rev 1151) @@ -1,329 +0,0 @@ - -%\VignetteIndexEntry{Mapping levels of a factor} -%\VignettePackage{gdata} -%\VignetteKeywords{levels, factor, manip} - -\documentclass[a4paper]{report} -\usepackage{Rnews} -\usepackage[round]{natbib} -\bibliographystyle{abbrvnat} - -\usepackage{Sweave} - - -\begin{document} - -\begin{article} - -\title{Mapping levels of a factor} -\subtitle{The \pkg{gdata} package} -\author{by Gregor Gorjanc} - -\maketitle - -\section{Introduction} - -Factors use levels attribute to store information on mapping between -internal integer codes and character values i.e. levels. First level is -mapped to internal integer code 1 and so on. Although some users do not -like factors, their use is more efficient in terms of storage than for -character vectors. Additionally, there are many functions in base \R{} that -provide additional value for factors. Sometimes users need to work with -internal integer codes and mapping them back to factor, especially when -interfacing external programs. Mapping information is also of interest if -there are many factors that should have the same set of levels. This note -describes \code{mapLevels} function, which is an utility function for -mapping the levels of a factor in \pkg{gdata} \footnote{from version 2.3.1} -package \citep{WarnesGdata}. - -\section{Description with examples} - -Function \code{mapLevels()} is an (S3) generic function and works on -\code{factor} and \code{character} atomic classes. It also works on -\code{list} and \code{data.frame} objects with previously mentioned atomic -classes. Function \code{mapLevels} produces a so called ``map'' with names -and values. Names are levels, while values can be internal integer codes or -(possibly other) levels. This will be clarified later on. Class of this -``map'' is \code{levelsMap}, if \code{x} in \code{mapLevels()} was atomic -or \code{listLevelsMap} otherwise - for \code{list} and \code{data.frame} -classes. The following example shows the creation and printout of such a -``map''. - -\begin{Schunk} -\begin{Sinput} -> library(gdata) -> (fac <- factor(c("B", "A", "Z", "D"))) -\end{Sinput} -\begin{Soutput} -[1] B A Z D -Levels: A B D Z -\end{Soutput} -\begin{Sinput} -> (map <- mapLevels(x=fac)) -\end{Sinput} -\begin{Soutput} -A B D Z -1 2 3 4 -\end{Soutput} -\end{Schunk} - -If we have to work with internal integer codes, we can transform factor to -integer and still get ``back the original factor'' with ``map'' used as -argument in \code{mapLevels<-} function as shown bellow. \code{mapLevels<-} -is also an (S3) generic function and works on same classes as -\code{mapLevels} plus \code{integer} atomic class. - -\begin{Schunk} -\begin{Sinput} -> (int <- as.integer(fac)) -\end{Sinput} -\begin{Soutput} -[1] 2 1 4 3 -\end{Soutput} -\begin{Sinput} -> mapLevels(x=int) <- map -> int -\end{Sinput} -\begin{Soutput} -[1] B A Z D -Levels: A B D Z -\end{Soutput} -\begin{Sinput} -> identical(fac, int) -\end{Sinput} -\begin{Soutput} -[1] TRUE -\end{Soutput} -\end{Schunk} - -Internally ``map'' (\code{levelsMap} class) is a \code{list} (see bellow), -but its print method unlists it for ease of inspection. ``Map'' from -example has all components of length 1. This is not mandatory as -\code{mapLevels<-} function is only a wrapper around workhorse function -\code{levels<-} and the later can accept \code{list} with components of -various lengths. - -\begin{Schunk} -\begin{Sinput} -> str(map) -\end{Sinput} -\begin{Soutput} -List of 4 - $ A: int 1 - $ B: int 2 - $ D: int 3 - $ Z: int 4 - - attr(*, "class")= chr "levelsMap" -\end{Soutput} -\end{Schunk} - -Although not of primary importance, this ``map'' can also be used to remap -factor levels as shown bellow. Components ``later'' in the map take over -the ``previous'' ones. Since this is not optimal I would rather recommend -other approaches for ``remapping'' the levels of a \code{factor}, say -\code{recode} in \pkg{car} package \citep{FoxCar}. - -\begin{Schunk} -\begin{Sinput} -> map[[2]] <- as.integer(c(1, 2)) -> map -\end{Sinput} -\begin{Soutput} -A B B D Z -1 1 2 3 4 -\end{Soutput} -\begin{Sinput} -> int <- as.integer(fac) -> mapLevels(x=int) <- map -> int -\end{Sinput} -\begin{Soutput} -[1] B B Z D -Levels: A B D Z -\end{Soutput} -\end{Schunk} - -Up to now examples showed ``map'' with internal integer codes for values -and levels for names. I call this integer ``map''. On the other hand -character ``map'' uses levels for values and (possibly other) levels for -names. This feature is a bit odd at first sight, but can be used to easily -unify levels and internal integer codes across several factors. Imagine -you have a factor that is for some reason split into two factors \code{f1} -and \code{f2} and that each factor does not have all levels. This is not -uncommon situation. - -\begin{Schunk} -\begin{Sinput} -> (f1 <- factor(c("A", "D", "C"))) -\end{Sinput} -\begin{Soutput} -[1] A D C -Levels: A C D -\end{Soutput} -\begin{Sinput} -> (f2 <- factor(c("B", "D", "C"))) -\end{Sinput} -\begin{Soutput} -[1] B D C -Levels: B C D -\end{Soutput} -\end{Schunk} - -If we work with this factors, we need to be careful as they do not have the -same set of levels. This can be solved with appropriately specifying -\code{levels} argument in creation of factors i.e. \code{levels=c("A", "B", - "C", "D")} or with proper use of \code{levels<-} function. I say proper -as it is very tempting to use: - -\begin{Schunk} -\begin{Sinput} -> fTest <- f1 -> levels(fTest) <- c("A", "B", "C", "D") -> fTest -\end{Sinput} -\begin{Soutput} -[1] A C B -Levels: A B C D -\end{Soutput} -\end{Schunk} - -Above example extends set of levels, but also changes level of 2nd and 3rd -element in \code{fTest}! Proper use of \code{levels<-} (as shown in -\code{levels} help page) would be: - -\begin{Schunk} -\begin{Sinput} -> fTest <- f1 -> levels(fTest) <- list(A="A", B="B", -+ C="C", D="D") -> fTest -\end{Sinput} -\begin{Soutput} -[1] A D C -Levels: A B C D -\end{Soutput} -\end{Schunk} - -Function \code{mapLevels} with character ``map'' can help us in such -scenarios to unify levels and internal integer codes across several -factors. Again the workhorse under this process is \code{levels<-} function -from base \R{}! Function \code{mapLevels<-} just controls the assignment of -(integer or character) ``map'' to \code{x}. Levels in \code{x} that match -``map'' values (internal integer codes or levels) are changed to ``map'' -names (possibly other levels) as shown in \code{levels} help page. Levels -that do not match are converted to \code{NA}. Integer ``map'' can be -applied to \code{integer} or \code{factor}, while character ``map'' can be -applied to \code{character} or \code{factor}. Result of \code{mapLevels<-} -is always a \code{factor} with possibly ``remapped'' levels. - -To get one joint character ``map'' for several factors, we need to put -factors in a \code{list} or \code{data.frame} and use arguments -\code{codes=FALSE} and \code{combine=TRUE}. Such map can then be used to -unify levels and internal integer codes. - -\begin{Schunk} -\begin{Sinput} -> (bigMap <- mapLevels(x=list(f1, f2), -+ codes=FALSE, -+ combine=TRUE)) -\end{Sinput} -\begin{Soutput} - A B C D -"A" "B" "C" "D" -\end{Soutput} -\begin{Sinput} -> mapLevels(f1) <- bigMap -> mapLevels(f2) <- bigMap -> f1 -\end{Sinput} -\begin{Soutput} -[1] A D C -Levels: A B C D -\end{Soutput} -\begin{Sinput} -> f2 -\end{Sinput} -\begin{Soutput} -[1] B D C -Levels: A B C D -\end{Soutput} -\begin{Sinput} -> cbind(as.character(f1), as.integer(f1), -+ as.character(f2), as.integer(f2)) -\end{Sinput} -\begin{Soutput} - [,1] [,2] [,3] [,4] -[1,] "A" "1" "B" "2" -[2,] "D" "4" "D" "4" -[3,] "C" "3" "C" "3" -\end{Soutput} -\end{Schunk} - -If we do not specify \code{combine=TRUE} (which is the default behaviour) -and \code{x} is a \code{list} or \code{data.frame}, \code{mapLevels} -returns ``map'' of class \code{listLevelsMap}. This is internally a -\code{list} of ``maps'' (\code{levelsMap} objects). Both -\code{listLevelsMap} and \code{levelsMap} objects can be passed to -\code{mapLevels<-} for \code{list}/\code{data.frame}. Recycling occurs when -length of \code{listLevelsMap} is not the same as number of -components/columns of a \code{list}/\code{data.frame}. - -Additional convenience methods are also implemented to ease the work with -``maps'': - -\begin{itemize} - -\item \code{is.levelsMap}, \code{is.listLevelsMap}, \code{as.levelsMap} and - \code{as.listLevelsMap} for testing and coercion of user defined - ``maps'', - -\item \code{"["} for subsetting, - -\item \code{c} for combining \code{levelsMap} or \code{listLevelsMap} - objects; argument \code{recursive=TRUE} can be used to coerce - \code{listLevelsMap} to \code{levelsMap}, for example \code{c(llm1, llm2, - recursive=TRUE)} and - -\item \code{unique} and \code{sort} for \code{levelsMap}. - -\end{itemize} - -\section{Summary} - -Functions \code{mapLevels} and \code{mapLevels<-} can help users to map -internal integer codes to factor levels and unify levels as well as -internal integer codes among several factors. I welcome any comments or -suggestions. - -% \bibliography{refs} -\begin{thebibliography}{1} -\providecommand{\natexlab}[1]{#1} -\providecommand{\url}[1]{\texttt{#1}} -\expandafter\ifx\csname urlstyle\endcsname\relax - \providecommand{\doi}[1]{doi: #1}\else - \providecommand{\doi}{doi: \begingroup \urlstyle{rm}\Url}\fi - -\bibitem[Fox(2006)]{FoxCar} -J.~Fox. -\newblock \emph{car: Companion to Applied Regression}, 2006. -\newblock URL \url{http://socserv.socsci.mcmaster.ca/jfox/}. -\newblock R package version 1.1-1. - -\bibitem[Warnes(2006)]{WarnesGdata} -G.~R. Warnes. -\newblock \emph{gdata: Various R programming tools for data manipulation}, - 2006. -\newblock URL - \url{http://cran.r-project.org/src/contrib/Descriptions/gdata.html}. -\newblock R package version 2.3.1. Includes R source code and/or documentation - contributed by Ben Bolker, Gregor Gorjanc and Thomas Lumley. - -\end{thebibliography} - -\address{Gregor Gorjanc\\ - University of Ljubljana, Slovenia\\ -\email{gre...@bf...}} - -\end{article} - -\end{document} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2007-08-20 10:17:41
|
Revision: 1150 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1150&view=rev Author: ggorjan Date: 2007-08-20 03:17:37 -0700 (Mon, 20 Aug 2007) Log Message: ----------- a real vignette Modified Paths: -------------- trunk/gdata/inst/doc/mapLevels.pdf trunk/gdata/inst/doc/mapLevels.tex Added Paths: ----------- trunk/gdata/inst/doc/mapLevels.Rnw Added: trunk/gdata/inst/doc/mapLevels.Rnw =================================================================== --- trunk/gdata/inst/doc/mapLevels.Rnw (rev 0) +++ trunk/gdata/inst/doc/mapLevels.Rnw 2007-08-20 10:17:37 UTC (rev 1150) @@ -0,0 +1,229 @@ + +%\VignetteIndexEntry{Mapping levels of a factor} +%\VignettePackage{gdata} +%\VignetteKeywords{levels, factor, manip} + +\documentclass[a4paper]{report} +\usepackage{Rnews} +\usepackage[round]{natbib} +\bibliographystyle{abbrvnat} + +\usepackage{Sweave} +\SweaveOpts{strip.white=all, keep.source=TRUE} + +\begin{document} + +\begin{article} + +\title{Mapping levels of a factor} +\subtitle{The \pkg{gdata} package} +\author{by Gregor Gorjanc} + +\maketitle + +\section{Introduction} + +Factors use levels attribute to store information on mapping between +internal integer codes and character values i.e. levels. First level is +mapped to internal integer code 1 and so on. Although some users do not +like factors, their use is more efficient in terms of storage than for +character vectors. Additionally, there are many functions in base \R{} that +provide additional value for factors. Sometimes users need to work with +internal integer codes and mapping them back to factor, especially when +interfacing external programs. Mapping information is also of interest if +there are many factors that should have the same set of levels. This note +describes \code{mapLevels} function, which is an utility function for +mapping the levels of a factor in \pkg{gdata} \footnote{from version 2.3.1} +package \citep{WarnesGdata}. + +\section{Description with examples} + +Function \code{mapLevels()} is an (S3) generic function and works on +\code{factor} and \code{character} atomic classes. It also works on +\code{list} and \code{data.frame} objects with previously mentioned atomic +classes. Function \code{mapLevels} produces a so called ``map'' with names +and values. Names are levels, while values can be internal integer codes or +(possibly other) levels. This will be clarified later on. Class of this +``map'' is \code{levelsMap}, if \code{x} in \code{mapLevels()} was atomic +or \code{listLevelsMap} otherwise - for \code{list} and \code{data.frame} +classes. The following example shows the creation and printout of such a +``map''. + +<<ex01>>= +library(gdata) +(fac <- factor(c("B", "A", "Z", "D"))) +(map <- mapLevels(x=fac)) +@ + +If we have to work with internal integer codes, we can transform factor to +integer and still get ``back the original factor'' with ``map'' used as +argument in \code{mapLevels<-} function as shown bellow. \code{mapLevels<-} +is also an (S3) generic function and works on same classes as +\code{mapLevels} plus \code{integer} atomic class. + +<<ex02>>= +(int <- as.integer(fac)) +mapLevels(x=int) <- map +int +identical(fac, int) +@ + +Internally ``map'' (\code{levelsMap} class) is a \code{list} (see bellow), +but its print method unlists it for ease of inspection. ``Map'' from +example has all components of length 1. This is not mandatory as +\code{mapLevels<-} function is only a wrapper around workhorse function +\code{levels<-} and the later can accept \code{list} with components of +various lengths. + +<<ex03>>= +str(map) +@ + +Although not of primary importance, this ``map'' can also be used to remap +factor levels as shown bellow. Components ``later'' in the map take over +the ``previous'' ones. Since this is not optimal I would rather recommend +other approaches for ``remapping'' the levels of a \code{factor}, say +\code{recode} in \pkg{car} package \citep{FoxCar}. + +<<ex04>>= +map[[2]] <- as.integer(c(1, 2)) +map +int <- as.integer(fac) +mapLevels(x=int) <- map +int +@ + +Up to now examples showed ``map'' with internal integer codes for values +and levels for names. I call this integer ``map''. On the other hand +character ``map'' uses levels for values and (possibly other) levels for +names. This feature is a bit odd at first sight, but can be used to easily +unify levels and internal integer codes across several factors. Imagine +you have a factor that is for some reason split into two factors \code{f1} +and \code{f2} and that each factor does not have all levels. This is not +uncommon situation. + +<<ex05>>= +(f1 <- factor(c("A", "D", "C"))) +(f2 <- factor(c("B", "D", "C"))) +@ + +If we work with this factors, we need to be careful as they do not have the +same set of levels. This can be solved with appropriately specifying +\code{levels} argument in creation of factors i.e. \code{levels=c("A", "B", + "C", "D")} or with proper use of \code{levels<-} function. I say proper +as it is very tempting to use: + +<<ex06>>= +fTest <- f1 +levels(fTest) <- c("A", "B", "C", "D") +fTest +@ + +Above example extends set of levels, but also changes level of 2nd and 3rd +element in \code{fTest}! Proper use of \code{levels<-} (as shown in +\code{levels} help page) would be: + +<<ex07>>= +fTest <- f1 +levels(fTest) <- list(A="A", B="B", + C="C", D="D") +fTest +@ + +Function \code{mapLevels} with character ``map'' can help us in such +scenarios to unify levels and internal integer codes across several +factors. Again the workhorse under this process is \code{levels<-} function +from base \R{}! Function \code{mapLevels<-} just controls the assignment of +(integer or character) ``map'' to \code{x}. Levels in \code{x} that match +``map'' values (internal integer codes or levels) are changed to ``map'' +names (possibly other levels) as shown in \code{levels} help page. Levels +that do not match are converted to \code{NA}. Integer ``map'' can be +applied to \code{integer} or \code{factor}, while character ``map'' can be +applied to \code{character} or \code{factor}. Result of \code{mapLevels<-} +is always a \code{factor} with possibly ``remapped'' levels. + +To get one joint character ``map'' for several factors, we need to put +factors in a \code{list} or \code{data.frame} and use arguments +\code{codes=FALSE} and \code{combine=TRUE}. Such map can then be used to +unify levels and internal integer codes. + +<<ex08>>= +(bigMap <- mapLevels(x=list(f1, f2), + codes=FALSE, + combine=TRUE)) +mapLevels(f1) <- bigMap +mapLevels(f2) <- bigMap +f1 +f2 +cbind(as.character(f1), as.integer(f1), + as.character(f2), as.integer(f2)) +@ + +If we do not specify \code{combine=TRUE} (which is the default behaviour) +and \code{x} is a \code{list} or \code{data.frame}, \code{mapLevels} +returns ``map'' of class \code{listLevelsMap}. This is internally a +\code{list} of ``maps'' (\code{levelsMap} objects). Both +\code{listLevelsMap} and \code{levelsMap} objects can be passed to +\code{mapLevels<-} for \code{list}/\code{data.frame}. Recycling occurs when +length of \code{listLevelsMap} is not the same as number of +components/columns of a \code{list}/\code{data.frame}. + +Additional convenience methods are also implemented to ease the work with +``maps'': + +\begin{itemize} + +\item \code{is.levelsMap}, \code{is.listLevelsMap}, \code{as.levelsMap} and + \code{as.listLevelsMap} for testing and coercion of user defined + ``maps'', + +\item \code{"["} for subsetting, + +\item \code{c} for combining \code{levelsMap} or \code{listLevelsMap} + objects; argument \code{recursive=TRUE} can be used to coerce + \code{listLevelsMap} to \code{levelsMap}, for example \code{c(llm1, llm2, + recursive=TRUE)} and + +\item \code{unique} and \code{sort} for \code{levelsMap}. + +\end{itemize} + +\section{Summary} + +Functions \code{mapLevels} and \code{mapLevels<-} can help users to map +internal integer codes to factor levels and unify levels as well as +internal integer codes among several factors. I welcome any comments or +suggestions. + +% \bibliography{refs} +\begin{thebibliography}{1} +\providecommand{\natexlab}[1]{#1} +\providecommand{\url}[1]{\texttt{#1}} +\expandafter\ifx\csname urlstyle\endcsname\relax + \providecommand{\doi}[1]{doi: #1}\else + \providecommand{\doi}{doi: \begingroup \urlstyle{rm}\Url}\fi + +\bibitem[Fox(2006)]{FoxCar} +J.~Fox. +\newblock \emph{car: Companion to Applied Regression}, 2006. +\newblock URL \url{http://socserv.socsci.mcmaster.ca/jfox/}. +\newblock R package version 1.1-1. + +\bibitem[Warnes(2006)]{WarnesGdata} +G.~R. Warnes. +\newblock \emph{gdata: Various R programming tools for data manipulation}, + 2006. +\newblock URL + \url{http://cran.r-project.org/src/contrib/Descriptions/gdata.html}. +\newblock R package version 2.3.1. Includes R source code and/or documentation + contributed by Ben Bolker, Gregor Gorjanc and Thomas Lumley. + +\end{thebibliography} + +\address{Gregor Gorjanc\\ + University of Ljubljana, Slovenia\\ +\email{gre...@bf...}} + +\end{article} + +\end{document} Property changes on: trunk/gdata/inst/doc/mapLevels.Rnw ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/gdata/inst/doc/mapLevels.pdf =================================================================== (Binary files differ) Modified: trunk/gdata/inst/doc/mapLevels.tex =================================================================== --- trunk/gdata/inst/doc/mapLevels.tex 2007-08-20 10:00:38 UTC (rev 1149) +++ trunk/gdata/inst/doc/mapLevels.tex 2007-08-20 10:17:37 UTC (rev 1150) @@ -1,3 +1,8 @@ + +%\VignetteIndexEntry{Mapping levels of a factor} +%\VignettePackage{gdata} +%\VignetteKeywords{levels, factor, manip} + \documentclass[a4paper]{report} \usepackage{Rnews} \usepackage[round]{natbib} @@ -3,10 +8,13 @@ \bibliographystyle{abbrvnat} +\usepackage{Sweave} + + \begin{document} \begin{article} \title{Mapping levels of a factor} -\subtitle{The gdata package} +\subtitle{The \pkg{gdata} package} \author{by Gregor Gorjanc} @@ -41,15 +49,23 @@ classes. The following example shows the creation and printout of such a ``map''. -\begin{smallverbatim} +\begin{Schunk} +\begin{Sinput} > library(gdata) > (fac <- factor(c("B", "A", "Z", "D"))) +\end{Sinput} +\begin{Soutput} [1] B A Z D Levels: A B D Z +\end{Soutput} +\begin{Sinput} > (map <- mapLevels(x=fac)) -A B D Z -1 2 3 4 -\end{smallverbatim} +\end{Sinput} +\begin{Soutput} +A B D Z +1 2 3 4 +\end{Soutput} +\end{Schunk} If we have to work with internal integer codes, we can transform factor to integer and still get ``back the original factor'' with ``map'' used as @@ -57,16 +73,28 @@ is also an (S3) generic function and works on same classes as \code{mapLevels} plus \code{integer} atomic class. -\begin{smallverbatim} +\begin{Schunk} +\begin{Sinput} > (int <- as.integer(fac)) +\end{Sinput} +\begin{Soutput} [1] 2 1 4 3 +\end{Soutput} +\begin{Sinput} > mapLevels(x=int) <- map > int +\end{Sinput} +\begin{Soutput} [1] B A Z D Levels: A B D Z +\end{Soutput} +\begin{Sinput} > identical(fac, int) +\end{Sinput} +\begin{Soutput} [1] TRUE -\end{smallverbatim} +\end{Soutput} +\end{Schunk} Internally ``map'' (\code{levelsMap} class) is a \code{list} (see bellow), but its print method unlists it for ease of inspection. ``Map'' from @@ -75,15 +103,19 @@ \code{levels<-} and the later can accept \code{list} with components of various lengths. -\begin{smallverbatim} +\begin{Schunk} +\begin{Sinput} > str(map) +\end{Sinput} +\begin{Soutput} List of 4 $ A: int 1 $ B: int 2 $ D: int 3 $ Z: int 4 - attr(*, "class")= chr "levelsMap" -\end{smallverbatim} +\end{Soutput} +\end{Schunk} Although not of primary importance, this ``map'' can also be used to remap factor levels as shown bellow. Components ``later'' in the map take over @@ -91,17 +123,25 @@ other approaches for ``remapping'' the levels of a \code{factor}, say \code{recode} in \pkg{car} package \citep{FoxCar}. -\begin{smallverbatim} +\begin{Schunk} +\begin{Sinput} > map[[2]] <- as.integer(c(1, 2)) > map -A B B D Z -1 1 2 3 4 +\end{Sinput} +\begin{Soutput} +A B B D Z +1 1 2 3 4 +\end{Soutput} +\begin{Sinput} > int <- as.integer(fac) > mapLevels(x=int) <- map > int +\end{Sinput} +\begin{Soutput} [1] B B Z D Levels: A B D Z -\end{smallverbatim} +\end{Soutput} +\end{Schunk} Up to now examples showed ``map'' with internal integer codes for values and levels for names. I call this integer ``map''. On the other hand @@ -112,14 +152,22 @@ and \code{f2} and that each factor does not have all levels. This is not uncommon situation. -\begin{smallverbatim} +\begin{Schunk} +\begin{Sinput} > (f1 <- factor(c("A", "D", "C"))) +\end{Sinput} +\begin{Soutput} [1] A D C Levels: A C D +\end{Soutput} +\begin{Sinput} > (f2 <- factor(c("B", "D", "C"))) +\end{Sinput} +\begin{Soutput} [1] B D C Levels: B C D -\end{smallverbatim} +\end{Soutput} +\end{Schunk} If we work with this factors, we need to be careful as they do not have the same set of levels. This can be solved with appropriately specifying @@ -127,25 +175,34 @@ "C", "D")} or with proper use of \code{levels<-} function. I say proper as it is very tempting to use: -\begin{smallverbatim} +\begin{Schunk} +\begin{Sinput} > fTest <- f1 > levels(fTest) <- c("A", "B", "C", "D") > fTest +\end{Sinput} +\begin{Soutput} [1] A C B Levels: A B C D -\end{smallverbatim} +\end{Soutput} +\end{Schunk} Above example extends set of levels, but also changes level of 2nd and 3rd element in \code{fTest}! Proper use of \code{levels<-} (as shown in \code{levels} help page) would be: -\begin{smallverbatim} +\begin{Schunk} +\begin{Sinput} > fTest <- f1 -> levels(fTest) <- list(A="A", B="B", C="C", D="D") +> levels(fTest) <- list(A="A", B="B", ++ C="C", D="D") > fTest +\end{Sinput} +\begin{Soutput} [1] A D C Levels: A B C D -\end{smallverbatim} +\end{Soutput} +\end{Schunk} Function \code{mapLevels} with character ``map'' can help us in such scenarios to unify levels and internal integer codes across several @@ -159,31 +216,48 @@ applied to \code{character} or \code{factor}. Result of \code{mapLevels<-} is always a \code{factor} with possibly ``remapped'' levels. -To get one joint character ``map'' for several factors, we need to -put factors in a \code{list} or \code{data.frame} and use arguments +To get one joint character ``map'' for several factors, we need to put +factors in a \code{list} or \code{data.frame} and use arguments \code{codes=FALSE} and \code{combine=TRUE}. Such map can then be used to unify levels and internal integer codes. -\begin{smallverbatim} -> (bigMap <- mapLevels(x=list(f1, f2), codes=FALSE, +\begin{Schunk} +\begin{Sinput} +> (bigMap <- mapLevels(x=list(f1, f2), ++ codes=FALSE, + combine=TRUE)) - A B C D -"A" "B" "C" "D" +\end{Sinput} +\begin{Soutput} + A B C D +"A" "B" "C" "D" +\end{Soutput} +\begin{Sinput} > mapLevels(f1) <- bigMap > mapLevels(f2) <- bigMap > f1 +\end{Sinput} +\begin{Soutput} [1] A D C Levels: A B C D +\end{Soutput} +\begin{Sinput} > f2 +\end{Sinput} +\begin{Soutput} [1] B D C Levels: A B C D +\end{Soutput} +\begin{Sinput} > cbind(as.character(f1), as.integer(f1), + as.character(f2), as.integer(f2)) +\end{Sinput} +\begin{Soutput} [,1] [,2] [,3] [,4] -[1,] "A" "1" "B" "2" -[2,] "D" "4" "D" "4" -[3,] "C" "3" "C" "3" -\end{smallverbatim} +[1,] "A" "1" "B" "2" +[2,] "D" "4" "D" "4" +[3,] "C" "3" "C" "3" +\end{Soutput} +\end{Schunk} If we do not specify \code{combine=TRUE} (which is the default behaviour) and \code{x} is a \code{list} or \code{data.frame}, \code{mapLevels} @@ -235,7 +309,7 @@ \newblock URL \url{http://socserv.socsci.mcmaster.ca/jfox/}. \newblock R package version 1.1-1. -\bibitem[Warnes.(2006)]{WarnesGdata} +\bibitem[Warnes(2006)]{WarnesGdata} G.~R. Warnes. \newblock \emph{gdata: Various R programming tools for data manipulation}, 2006. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2007-08-20 10:00:43
|
Revision: 1149 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1149&view=rev Author: ggorjan Date: 2007-08-20 03:00:38 -0700 (Mon, 20 Aug 2007) Log Message: ----------- a real vignette Modified Paths: -------------- trunk/gdata/inst/doc/unknown.pdf Added Paths: ----------- trunk/gdata/inst/doc/unknown.Rnw Removed Paths: ------------- trunk/gdata/inst/doc/unknown.tex Added: trunk/gdata/inst/doc/unknown.Rnw =================================================================== --- trunk/gdata/inst/doc/unknown.Rnw (rev 0) +++ trunk/gdata/inst/doc/unknown.Rnw 2007-08-20 10:00:38 UTC (rev 1149) @@ -0,0 +1,272 @@ + +%\VignetteIndexEntry{Working with Unknown Values} +%\VignettePackage{gdata} +%\VignetteKeywords{unknown, missing, manip} + +\documentclass[a4paper]{report} +\usepackage{Rnews} +\usepackage[round]{natbib} +\bibliographystyle{abbrvnat} + +\usepackage{Sweave} +\SweaveOpts{strip.white=all, keep.source=TRUE} + +\begin{document} + +\begin{article} + +\title{Working with Unknown Values} +\subtitle{The \pkg{gdata} package} +\author{by Gregor Gorjanc} + +\maketitle + +This vignette has been published as \cite{Gorjanc}. + +\section{Introduction} + +Unknown or missing values can be represented in various ways. For example +SAS uses \code{.}~(dot), while \R{} uses \code{NA}, which we can read as +Not Available. When we import data into \R{}, say via \code{read.table} or +its derivatives, conversion of blank fields to \code{NA} (according to +\code{read.table} help) is done for \code{logical}, \code{integer}, +\code{numeric} and \code{complex} classes. Additionally, the +\code{na.strings} argument can be used to specify values that should also +be converted to \code{NA}. Inversely, there is an argument \code{na} in +\code{write.table} and its derivatives to define value that will replace +\code{NA} in exported data. There are also other ways to import/export data +into \R{} as described in the {\emph R Data Import/Export} manual +\citep{RImportExportManual}. However, all approaches lack the possibility +to define unknown value(s) for some particular column. It is possible that +an unknown value in one column is a valid value in another column. For +example, I have seen many datasets where values such as 0, -9, 999 and +specific dates are used as column specific unknown values. + +This note describes a set of functions in package \pkg{gdata}\footnote{ + package version 2.3.1} \citep{WarnesGdata}: \code{isUnknown}, +\code{unknownToNA} and \code{NAToUnknown}, which can help with testing for +unknown values and conversions between unknown values and \code{NA}. All +three functions are generic (S3) and were tested (at the time of writing) +to work with: \code{integer}, \code{numeric}, \code{character}, +\code{factor}, \code{Date}, \code{POSIXct}, \code{POSIXlt}, \code{list}, +\code{data.frame} and \code{matrix} classes. + +\section{Description with examples} + +The following examples show simple usage of these functions on +\code{numeric} and \code{factor} classes, where value \code{0} (beside +\code{NA}) should be treated as an unknown value: + +<<ex01>>= +library("gdata") +xNum <- c(0, 6, 0, 7, 8, 9, NA) +isUnknown(x=xNum) +@ + +The default unknown value in \code{isUnknown} is \code{NA}, which means +that output is the same as \code{is.na} --- at least for atomic +classes. However, we can pass the argument \code{unknown} to define which +values should be treated as unknown: + +<<ex02>>= +isUnknown(x=xNum, unknown=0) +@ + +This skipped \code{NA}, but we can get the expected answer after +appropriately adding \code{NA} into the argument \code{unknown}: + +<<ex03>>= +isUnknown(x=xNum, unknown=c(0, NA)) +@ + +Now, we can change all unknown values to \code{NA} with \code{unknownToNA}. +There is clearly no need to add \code{NA} here. This step is very handy +after importing data from an external source, where many different unknown +values might be used. Argument \code{warning=TRUE} can be used, if there is +a need to be warned about ``original'' \code{NA}s: + +<<ex04>>= +(xNum2 <- unknownToNA(x=xNum, unknown=0)) +@ + +Prior to export from \R{}, we might want to change unknown values +(\code{NA} in \R{}) to some other value. Function \code{NAToUnknown} can be +used for this: + +<<ex05>>= +NAToUnknown(x=xNum2, unknown=999) +@ + +Converting \code{NA} to a value that already exists in \code{x} issues an +error, but \code{force=TRUE} can be used to overcome this if needed. But be +warned that there is no way back from this step: + +<<ex06>>= +NAToUnknown(x=xNum2, unknown=7, force=TRUE) +@ + +Examples below show all peculiarities with class \code{factor}. +\code{unknownToNA} removes \code{unknown} value from levels and inversely +\code{NAToUnknown} adds it with a warning. Additionally, \code{"NA"} is +properly distinguished from \code{NA}. It can also be seen that the +argument \code{unknown} in functions \code{isUnknown} and +\code{unknownToNA} need not match the class of \code{x} (otherwise factor +should be used) as the test is internally done with \code{\%in\%}, which +nicely resolves coercing issues. + +<<ex07>>= +(xFac <- factor(c(0, "BA", "RA", "BA", NA, "NA"))) +isUnknown(x=xFac) +isUnknown(x=xFac, unknown=0) +isUnknown(x=xFac, unknown=c(0, NA)) +isUnknown(x=xFac, unknown=c(0, "NA")) +isUnknown(x=xFac, unknown=c(0, "NA", NA)) + +(xFac <- unknownToNA(x=xFac, unknown=0)) +(xFac <- NAToUnknown(x=xFac, unknown=0)) +@ + +These two examples with classes \code{numeric} and \code{factor} are fairly +simple and we could get the same results with one or two lines of \R{} +code. The real benefit of the set of functions presented here is in +\code{list} and \code{data.frame} methods, where \code{data.frame} methods +are merely wrappers for \code{list} methods. + +We need additional flexibility for \code{list}/\code{data.frame} methods, +due to possibly having multiple unknown values that can be different among +\code{list} components or \code{data.frame} columns. For these two methods, +the argument \code{unknown} can be either a \code{vector} or \code{list}, +both possibly named. Of course, greater flexibility (defining multiple +unknown values per component/column) can be achieved with a \code{list}. + +When a \code{vector}/\code{list} object passed to the argument +\code{unknown} is not named, the first value/component of a +\code{vector}/\code{list} matches the first component/column of a +\code{list}/\code{data.frame}. This can be quite error prone, especially +with \code{vectors}. Therefore, I encourage the use of a \code{list}. In +case \code{vector}/\code{list} passed to argument \code{unknown} is named, +names are matched to names of \code{list} or \code{data.frame}. If lengths +of \code{unknown} and \code{list} or \code{data.frame} do not match, +recycling occurs. + +The example below illustrates the application of the described functions to +a list which is composed of previously defined and modified numeric +(\code{xNum}) and factor (\code{xFac}) classes. First, function +\code{isUnknown} is used with \code{0} as an unknown value. Note that we +get \code{FALSE} for \code{NA}s as has been the case in the first example. + +<<ex08>>= +(xList <- list(a=xNum, b=xFac)) +isUnknown(x=xList, unknown=0) +@ + +We need to add \code{NA} as an unknown value. However, we do not get the +expected result this way! + +<<ex09>>= +isUnknown(x=xList, unknown=c(0, NA)) +@ + +This is due to matching of values in the argument \code{unknown} and +components in a \code{list}; i.e., \code{0} is used for component \code{a} +and \code{NA} for component \code{b}. Therefore, it is less error prone +and more flexible to pass a \code{list} (preferably a named list) to the +argument \code{unknown}, as shown below. + +<<ex10>>= +(xList1 <- unknownToNA(x=xList, + unknown=list(b=c(0, "NA"), + a=0))) +@ + +Changing \code{NA}s to some other value (only one per component/column) can +be accomplished as follows: + +<<ex11>>= +NAToUnknown(x=xList1, + unknown=list(b="no", a=0)) +@ + +A named component \code{.default} of a \code{list} passed to argument +\code{unknown} has a special meaning as it will match a component/column +with that name and any other not defined in \code{unknown}. As such it is +very useful if the number of components/columns with the same unknown +value(s) is large. Consider a wide \code{data.frame} named \code{df}. Now +\code{.default} can be used to define unknown value for several columns: + +<<ex12, echo=FALSE>>= +df <- data.frame(col1=c(0, 1, 999, 2), + col2=c("a", "b", "c", "unknown"), + col3=c(0, 1, 2, 3), + col4=c(0, 1, 2, 2)) +@ + +<<ex13>>= +tmp <- list(.default=0, + col1=999, + col2="unknown") +(df2 <- unknownToNA(x=df, + unknown=tmp)) +@ + +If there is a need to work only on some components/columns you can of +course ``skip'' columns with standard \R{} mechanisms, i.e., +by subsetting \code{list} or \code{data.frame} objects: + +<<ex14>>= +df2 <- df +cols <- c("col1", "col2") +tmp <- list(col1=999, + col2="unknown") +df2[, cols] <- unknownToNA(x=df[, cols], + unknown=tmp) +df2 +@ + +\section{Summary} + +Functions \code{isUnknown}, \code{unknownToNA} and \code{NAToUnknown} +provide a useful interface to work with various representations of +unknown/missing values. Their use is meant primarily for shaping the data +after importing to or before exporting from \R{}. I welcome any comments or +suggestions. + +% \bibliography{refs} + +\begin{thebibliography}{1} +\providecommand{\natexlab}[1]{#1} +\providecommand{\url}[1]{\texttt{#1}} +\expandafter\ifx\csname urlstyle\endcsname\relax + \providecommand{\doi}[1]{doi: #1}\else + \providecommand{\doi}{doi: \begingroup \urlstyle{rm}\Url}\fi + +\bibitem[Gorjanc(2007)]{Gorjanc} +G.~Gorjanc. +\newblock Working with unknown values: the gdata package. +\newblock \emph{R News}, 7\penalty0 (1):\penalty0 24--26, 2007. +\newblock URL \url{http://CRAN.R-project.org/doc/Rnews/Rnews_2007-1.pdf}. + +\bibitem[{R Development Core Team}(2006)]{RImportExportManual} +{R Development Core Team}. +\newblock \emph{R Data Import/Export}, 2006. +\newblock URL \url{http://cran.r-project.org/manuals.html}. +\newblock ISBN 3-900051-10-0. + +\bibitem[Warnes (2006)]{WarnesGdata} +G.~R. Warnes. +\newblock \emph{gdata: Various R programming tools for data manipulation}, + 2006. +\newblock URL + \url{http://cran.r-project.org/src/contrib/Descriptions/gdata.html}. +\newblock R package version 2.3.1. Includes R source code and/or documentation + contributed by Ben Bolker, Gregor Gorjanc and Thomas Lumley. + +\end{thebibliography} + +\address{Gregor Gorjanc\\ + University of Ljubljana, Slovenia\\ +\email{gre...@bf...}} + +\end{article} + +\end{document} Property changes on: trunk/gdata/inst/doc/unknown.Rnw ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/gdata/inst/doc/unknown.pdf =================================================================== (Binary files differ) Deleted: trunk/gdata/inst/doc/unknown.tex =================================================================== --- trunk/gdata/inst/doc/unknown.tex 2007-08-20 08:18:26 UTC (rev 1148) +++ trunk/gdata/inst/doc/unknown.tex 2007-08-20 10:00:38 UTC (rev 1149) @@ -1,303 +0,0 @@ -\documentclass[a4paper]{report} -\usepackage{Rnews} -\usepackage[round]{natbib} -\bibliographystyle{abbrvnat} - -\begin{document} - -\begin{article} - -\title{Working with Unknown Values} -\subtitle{The \pkg{gdata} package} -\author{by Gregor Gorjanc} - -\maketitle - -This vignette has been published as \cite{Gorjanc}. - -\section{Introduction} - -Unknown or missing values can be represented in various ways. For example -SAS uses \code{.}~(dot), while \R{} uses \code{NA}, which we can read as -Not Available. When we import data into \R{}, say via \code{read.table} or -its derivatives, conversion of blank fields to \code{NA} (according to -\code{read.table} help) is done for \code{logical}, \code{integer}, -\code{numeric} and \code{complex} classes. Additionally, -the \code{na.strings} -argument can be used to specify values that should also be converted to -\code{NA}. Inversely, there is an argument \code{na} in \code{write.table} -and its derivatives to define value that will replace \code{NA} in exported -data. There are also other ways to import/export data into \R{} as -described in the {\emph R Data Import/Export} manual \citep{RImportExportManual}. -However, all approaches lack the possibility to define unknown value(s) for -some particular column. It is possible that an unknown value in one column is a -valid value in another column. For example, I have seen many datasets where -values such as 0, -9, 999 and specific dates are used as column specific unknown -values. - -This note describes a set of functions in package \pkg{gdata}\footnote{ -package version 2.3.1} \citep{WarnesGdata}: \code{isUnknown}, -\code{unknownToNA} and \code{NAToUnknown}, which can help with testing for -unknown values and conversions between unknown values and \code{NA}. All -three functions are generic (S3) and were tested (at the time of writing) -to work with: \code{integer}, \code{numeric}, \code{character}, -\code{factor}, \code{Date}, \code{POSIXct}, \code{POSIXlt}, \code{list}, -\code{data.frame} and \code{matrix} classes. - -\section{Description with examples} - -The following examples show simple usage of these functions on -\code{numeric} and \code{factor} classes, where value \code{0} (beside -\code{NA}) should be treated as an unknown value: - -\begin{smallverbatim} -> library("gdata") -> xNum <- c(0, 6, 0, 7, 8, 9, NA) -> isUnknown(x=xNum) -[1] FALSE FALSE FALSE FALSE FALSE FALSE TRUE -\end{smallverbatim} - -The default unknown value in \code{isUnknown} is \code{NA}, which means -that output is the same as \code{is.na} --- at least for atomic -classes. However, we can pass the argument \code{unknown} to define which -values should be treated as unknown: - -\begin{smallverbatim} -> isUnknown(x=xNum, unknown=0) -[1] TRUE FALSE TRUE FALSE FALSE FALSE FALSE -\end{smallverbatim} - -This skipped \code{NA}, but we can get the expected answer after appropriately -adding \code{NA} into the argument \code{unknown}: - -\begin{smallverbatim} -> isUnknown(x=xNum, unknown=c(0, NA)) -[1] TRUE FALSE TRUE FALSE FALSE FALSE TRUE -\end{smallverbatim} - -Now, we can change all unknown values to \code{NA} with \code{unknownToNA}. -There is clearly no need to add \code{NA} here. This step is very handy -after importing data from an external source, where many different unknown -values might be used. Argument \code{warning=TRUE} can be used, if there is -a need to be warned about ``original'' \code{NA}s: - -\begin{smallverbatim} -> xNum2 <- unknownToNA(x=xNum, unknown=0) -[1] NA 6 NA 7 8 9 NA -\end{smallverbatim} - -Prior to export from \R{}, we might want to change unknown values (\code{NA} -in \R{}) to some other value. Function \code{NAToUnknown} can be used for -this: - -\begin{smallverbatim} -> NAToUnknown(x=xNum2, unknown=999) -[1] 999 6 999 7 8 9 999 -\end{smallverbatim} - -Converting \code{NA} to a value that already exists in \code{x} issues an -error, but \code{force=TRUE} can be used to overcome this if -needed. But be warned that there is no way back from this step: - -\begin{smallverbatim} -> NAToUnknown(x=xNum2, unknown=7, force=TRUE) -[1] 7 6 7 7 8 9 7 -\end{smallverbatim} - -Examples below show all peculiarities with class \code{factor}. -\code{unknownToNA} removes \code{unknown} value from levels and inversely -\code{NAToUnknown} adds it with a warning. Additionally, \code{"NA"} is -properly distinguished from \code{NA}. It can also be seen that the argument -\code{unknown} in functions \code{isUnknown} and \code{unknownToNA} need -not match the class of \code{x} (otherwise factor should be used) as the test -is internally done with \code{\%in\%}, which nicely resolves coercing -issues. - -\begin{smallverbatim} -> xFac <- factor(c(0, "BA", "RA", "BA", NA, "NA")) -[1] 0 BA RA BA <NA> NA -Levels: 0 BA NA RA -> isUnknown(x=xFac) -[1] FALSE FALSE FALSE FALSE TRUE FALSE -> isUnknown(x=xFac, unknown=0) -[1] TRUE FALSE FALSE FALSE FALSE FALSE -> isUnknown(x=xFac, unknown=c(0, NA)) -[1] TRUE FALSE FALSE FALSE TRUE FALSE -> isUnknown(x=xFac, unknown=c(0, "NA")) -[1] TRUE FALSE FALSE FALSE FALSE TRUE -> isUnknown(x=xFac, unknown=c(0, "NA", NA)) -[1] TRUE FALSE FALSE FALSE TRUE TRUE - -> xFac <- unknownToNA(x=xFac, unknown=0) -[1] <NA> BA RA BA <NA> NA -Levels: BA NA RA -> xFac <- NAToUnknown(x=xFac, unknown=0) -[1] 0 BA RA BA 0 NA -Levels: 0 BA NA RA -Warning message: -new level is introduced: 0 -\end{smallverbatim} - -These two examples with classes \code{numeric} and \code{factor} are fairly simple and we -could get the same results with one or two lines of \R{} code. The real -benefit of the set of functions presented here is in \code{list} and -\code{data.frame} methods, where \code{data.frame} methods are merely -wrappers for \code{list} methods. - -We need additional flexibility for \code{list}/\code{data.frame} methods, -due to possibly having multiple unknown values that can be different -among \code{list} components or \code{data.frame} columns. For these two -methods, the argument \code{unknown} can be either a \code{vector} or -\code{list}, both possibly named. Of course, greater flexibility (defining -multiple unknown values per component/column) can be achieved with -a \code{list}. - -When a \code{vector}/\code{list} object passed to the argument \code{unknown} is not -named, the first value/component of a \code{vector}/\code{list} matches the first -component/column of a \code{list}/\code{data.frame}. This can be quite -error prone, especially with \code{vectors}. Therefore, I encourage the use of -a \code{list}. In case \code{vector}/\code{list} passed to argument -\code{unknown} is named, names are matched to names of \code{list} or -\code{data.frame}. If lengths of \code{unknown} and \code{list} or -\code{data.frame} do not match, recycling occurs. - -The example below illustrates the application of the -described functions to a list which is -composed of previously defined and modified numeric (\code{xNum}) and -factor (\code{xFac}) classes. First, function \code{isUnknown} is used with -\code{0} as an unknown value. Note that we get \code{FALSE} for \code{NA}s as -has been the case in the first example. - -\begin{smallverbatim} -> xList <- list(a=xNum, b=xFac) -$a -[1] 0 6 0 7 8 9 NA - -$b -[1] 0 BA RA BA 0 NA -Levels: 0 BA NA RA -> isUnknown(x=xList, unknown=0) -$a -[1] TRUE FALSE TRUE FALSE FALSE FALSE FALSE - -$b -[1] TRUE FALSE FALSE FALSE TRUE FALSE -\end{smallverbatim} - -We need to add \code{NA} as an unknown value. However, we do not get the -expected result this way! - -\begin{smallverbatim} -> isUnknown(x=xList, unknown=c(0, NA)) -$a -[1] TRUE FALSE TRUE FALSE FALSE FALSE FALSE - -$b -[1] FALSE FALSE FALSE FALSE FALSE FALSE -\end{smallverbatim} - -This is due to matching of values in the argument \code{unknown} and components -in a \code{list}; i.e., \code{0} is used for component \code{a} and \code{NA} -for component \code{b}. Therefore, it is less error prone and more -flexible to pass a \code{list} (preferably a named list) to the argument -\code{unknown}, as shown below. - -\begin{smallverbatim} -> xList1 <- unknownToNA(x=xList, -+ unknown=list(b=c(0, "NA"), a=0)) -$a -[1] NA 6 NA 7 8 9 NA - -$b -[1] <NA> BA RA BA <NA> <NA> -Levels: BA RA -\end{smallverbatim} - -Changing \code{NA}s to some other value (only one per component/column) can -be accomplished as follows: - -\begin{smallverbatim} -> NAToUnknown(x=xList1, unknown=list(b="no", a=0)) -$a -[1] 0 6 0 7 8 9 0 - -$b -[1] no BA RA BA no no -Levels: BA no RA - -Warning message: -new level is introduced: no -\end{smallverbatim} - -A named component \code{.default} of a \code{list} passed to argument -\code{unknown} has a special meaning as it will match a component/column with -that name and any other not defined in \code{unknown}. As such it is very -useful if the number of components/columns with the same unknown value(s) -is large. Consider a wide \code{data.frame} named \code{df}. Now -\code{.default} can be used to define unknown value for several columns: - -\begin{smallverbatim} -> df <- unknownToNA(x=df, -+ unknown=(.default=0, -+ col1=999, -+ col2="unknown")) -\end{smallverbatim} - -If there is a need to work only on some components/columns you can of -course ``skip'' columns with standard \R{} mechanisms, i.e., -by subsetting \code{list} or \code{data.frame} objects: - -\begin{smallverbatim} -> cols <- c("col1", "col2") -> df[, cols] <- unknownToNA(x=df[, cols], -+ unknown=(col1=999, -+ col2="unknown")) -\end{smallverbatim} - -\section{Summary} - -Functions \code{isUnknown}, \code{unknownToNA} and \code{NAToUnknown} -provide a useful interface to work with various representations of -unknown/missing values. Their use is meant primarily for shaping the data -after importing to or before exporting from \R{}. I welcome any comments or -suggestions. - -% \bibliography{refs} - -\begin{thebibliography}{1} -\providecommand{\natexlab}[1]{#1} -\providecommand{\url}[1]{\texttt{#1}} -\expandafter\ifx\csname urlstyle\endcsname\relax - \providecommand{\doi}[1]{doi: #1}\else - \providecommand{\doi}{doi: \begingroup \urlstyle{rm}\Url}\fi - -\bibitem[Gorjanc(2007)]{Gorjanc} -G.~Gorjanc. -\newblock Working with unknown values: the gdata package. -\newblock \emph{R News}, 7\penalty0 (1):\penalty0 24--26, 2007. -\newblock URL \url{http://CRAN.R-project.org/doc/Rnews/Rnews_2007-1.pdf}. - -\bibitem[{R Development Core Team}(2006)]{RImportExportManual} -{R Development Core Team}. -\newblock \emph{R Data Import/Export}, 2006. -\newblock URL \url{http://cran.r-project.org/manuals.html}. -\newblock ISBN 3-900051-10-0. - -\bibitem[Warnes (2006)]{WarnesGdata} -G.~R. Warnes. -\newblock \emph{gdata: Various R programming tools for data manipulation}, - 2006. -\newblock URL - \url{http://cran.r-project.org/src/contrib/Descriptions/gdata.html}. -\newblock R package version 2.3.1. Includes R source code and/or documentation - contributed by Ben Bolker, Gregor Gorjanc and Thomas Lumley. - -\end{thebibliography} - -\address{Gregor Gorjanc\\ - University of Ljubljana, Slovenia\\ -\email{gre...@bf...}} - -\end{article} - -\end{document} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2007-08-20 08:18:31
|
Revision: 1148 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1148&view=rev Author: ggorjan Date: 2007-08-20 01:18:26 -0700 (Mon, 20 Aug 2007) Log Message: ----------- additional keyword for searchig Modified Paths: -------------- trunk/gdata/man/unknown.Rd Modified: trunk/gdata/man/unknown.Rd =================================================================== --- trunk/gdata/man/unknown.Rd 2007-08-17 12:40:28 UTC (rev 1147) +++ trunk/gdata/man/unknown.Rd 2007-08-20 08:18:26 UTC (rev 1148) @@ -2,7 +2,7 @@ %-------------------------------------------------------------------------- % What: Change given unknown value to NA and vice versa man page % $Id$ -% Time-stamp: <2007-08-17 01:05:36 ggorjan> +% Time-stamp: <2007-08-17 20:18:54 ggorjan> %-------------------------------------------------------------------------- \name{unknownToNA} @@ -26,6 +26,8 @@ \alias{NAToUnknown.list} \alias{NAToUnknown.data.frame} +\concept{missing} + \title{Change unknown values to NA and vice versa} \description{ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2007-08-17 12:40:32
|
Revision: 1147 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1147&view=rev Author: ggorjan Date: 2007-08-17 05:40:28 -0700 (Fri, 17 Aug 2007) Log Message: ----------- keyword Modified Paths: -------------- trunk/gdata/man/unknown.Rd Modified: trunk/gdata/man/unknown.Rd =================================================================== --- trunk/gdata/man/unknown.Rd 2007-08-15 07:02:17 UTC (rev 1146) +++ trunk/gdata/man/unknown.Rd 2007-08-17 12:40:28 UTC (rev 1147) @@ -2,7 +2,7 @@ %-------------------------------------------------------------------------- % What: Change given unknown value to NA and vice versa man page % $Id$ -% Time-stamp: <2006-11-01 00:15:08 ggorjan> +% Time-stamp: <2007-08-17 01:05:36 ggorjan> %-------------------------------------------------------------------------- \name{unknownToNA} @@ -46,7 +46,7 @@ } \arguments{ - \item{x}{generic, object with \code{NA}} + \item{x}{generic, object with unknown value(s)} \item{unknown}{generic, value used instead of \code{NA}} \item{warning}{logical, issue warning if \code{x} already has \code{NA}} \item{force}{logical, force to apply already existing value in \code{x}} @@ -155,6 +155,7 @@ } \keyword{manip} +\keyword{NA} %-------------------------------------------------------------------------- % unknown.Rd ends here This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2007-08-15 06:06:11
|
Revision: 1145 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1145&view=rev Author: warnes Date: 2007-08-14 23:06:09 -0700 (Tue, 14 Aug 2007) Log Message: ----------- Fix reverse.c because we need to swap everything to match Big-Endian, rather than Little-Endian. Also, dont' call the macro. Modified Paths: -------------- trunk/SASxport/src/reverse.c Modified: trunk/SASxport/src/reverse.c =================================================================== --- trunk/SASxport/src/reverse.c 2007-08-15 06:04:57 UTC (rev 1144) +++ trunk/SASxport/src/reverse.c 2007-08-15 06:06:09 UTC (rev 1145) @@ -1,4 +1,4 @@ -#include "writeSAS.h" +//#include "writeSAS.h" #include <stdio.h> #include <string.h> @@ -6,30 +6,29 @@ #import <assert.h> #import <sys/types.h> -/* reverse: convert current byte order to little endian */ -void reverse( u_char *intp, size_t size) +/* reverse: convert current byte order to big endian */ +void reverse( unsigned char *intp, size_t size) { - static u_char endianTest[2] = {0x01,0x00}; + static unsigned char endianTest[2] = {0x01,0x00}; size_t i; - u_char tmp; + unsigned char tmp; #if !defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN) /* Test if we are on a big endian or little endian platform */ - if( (short) *endianTest == 1 ) + if( (short) *endianTest != 1 ) { - /* Little Endian */ - /* Do nothing */ + /* The native byte order is big endian, so do nothing */ + sprintf("Big Endian Machine!\n"); return; } #endif - /* Big Endian */ - /* Swap bytes */ + /* If native byte order is little endian, we need to swap bytes */ for(i=0; i < size/2; i++) { - tmp = (u_char) intp[i]; + tmp = (unsigned char) intp[i]; intp[i] = intp[size-i-1]; - intp[size-i] = tmp; + intp[size-i-1] = tmp; } return; @@ -39,41 +38,41 @@ /* test code */ void test_reverse() { - u_char byte_pattern[1] = { 0x00 }; - u_char byte_value = 0x00; + unsigned char byte_pattern[1] = { 0x00 }; + unsigned char byte_value = 0x00; - u_char short_pattern[2] = { 0x00, 0x01 }; /* NB: little endian byte pattern */ - short short_value = 0x0100; /* NB: hex is written big endian */ + unsigned char short_pattern[2] = { 0x01, 0x00 }; /* NB: big endian byte pattern */ + short short_value = 0x0100; /* NB: hex is also written big endian */ - u_char int_pattern[4] = { 0x0, 0x01, 0x02, 0x03 }; + unsigned char int_pattern[4] = { 0x03, 0x02, 0x01, 0x00 }; int int_value = 0x03020100; - u_char long_pattern[4] = { 0x0, 0x01, 0x02, 0x03 }; + unsigned char long_pattern[4] = { 0x03, 0x02, 0x01, 0x00 }; long long_value = 0x03020100; /* Do the reverse, then test */ /* byte */ - REVERSE( &byte_value, sizeof(u_char) ); - assert( (u_char) *byte_pattern == byte_value ); + reverse( &byte_value, sizeof(unsigned char) ); + assert( (unsigned char) *byte_pattern == byte_value ); /* short */ - REVERSE( &short_value, sizeof(short) ); + reverse( (unsigned char*) &short_value, sizeof(short) ); assert( *((short *) short_pattern) == short_value ); /* int */ - REVERSE( &int_value, sizeof(int) ); + reverse( (unsigned char*) &int_value, sizeof(int) ); assert( *((int *) int_pattern) == int_value ); /* long */ - REVERSE( &long_value, sizeof(long) ); + reverse( (unsigned char*) &long_value, sizeof(long) ); assert( *((long*) long_pattern) == long_value ); } #ifdef DO_TEST -int main(int argc, u_char *argv) +int main(int argc, char *argv) { test_reverse(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2007-08-15 06:04:58
|
Revision: 1144 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1144&view=rev Author: warnes Date: 2007-08-14 23:04:57 -0700 (Tue, 14 Aug 2007) Log Message: ----------- Restore reverse.c Added Paths: ----------- trunk/SASxport/src/reverse.c Copied: trunk/SASxport/src/reverse.c (from rev 1136, trunk/SASxport/src/reverse.c) =================================================================== --- trunk/SASxport/src/reverse.c (rev 0) +++ trunk/SASxport/src/reverse.c 2007-08-15 06:04:57 UTC (rev 1144) @@ -0,0 +1,83 @@ +#include "writeSAS.h" + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#import <assert.h> +#import <sys/types.h> + +/* reverse: convert current byte order to little endian */ +void reverse( u_char *intp, size_t size) +{ + static u_char endianTest[2] = {0x01,0x00}; + size_t i; + u_char tmp; + +#if !defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN) + /* Test if we are on a big endian or little endian platform */ + if( (short) *endianTest == 1 ) + { + /* Little Endian */ + /* Do nothing */ + return; + } +#endif + + /* Big Endian */ + /* Swap bytes */ + for(i=0; i < size/2; i++) + { + tmp = (u_char) intp[i]; + intp[i] = intp[size-i-1]; + intp[size-i] = tmp; + } + + return; +} + + +/* test code */ +void test_reverse() +{ + u_char byte_pattern[1] = { 0x00 }; + u_char byte_value = 0x00; + + u_char short_pattern[2] = { 0x00, 0x01 }; /* NB: little endian byte pattern */ + short short_value = 0x0100; /* NB: hex is written big endian */ + + u_char int_pattern[4] = { 0x0, 0x01, 0x02, 0x03 }; + int int_value = 0x03020100; + + u_char long_pattern[4] = { 0x0, 0x01, 0x02, 0x03 }; + long long_value = 0x03020100; + + /* Do the reverse, then test */ + + /* byte */ + REVERSE( &byte_value, sizeof(u_char) ); + assert( (u_char) *byte_pattern == byte_value ); + + /* short */ + REVERSE( &short_value, sizeof(short) ); + assert( *((short *) short_pattern) == short_value ); + + /* int */ + REVERSE( &int_value, sizeof(int) ); + assert( *((int *) int_pattern) == int_value ); + + /* long */ + REVERSE( &long_value, sizeof(long) ); + assert( *((long*) long_pattern) == long_value ); + +} + + +#ifdef DO_TEST +int main(int argc, u_char *argv) +{ + test_reverse(); +} + + + +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2007-08-15 03:17:12
|
Revision: 1143 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1143&view=rev Author: warnes Date: 2007-08-14 20:17:08 -0700 (Tue, 14 Aug 2007) Log Message: ----------- Minor reformatting Modified Paths: -------------- trunk/SASxport/DESCRIPTION Modified: trunk/SASxport/DESCRIPTION =================================================================== --- trunk/SASxport/DESCRIPTION 2007-08-15 03:14:42 UTC (rev 1142) +++ trunk/SASxport/DESCRIPTION 2007-08-15 03:17:08 UTC (rev 1143) @@ -13,10 +13,12 @@ includes code from Frank E. Harrell, Jr.'s Hmisc package, and floating point conversion code from SAS techical support document TS-140 "THE RECORD LAYOUT OF A DATA SET IN SAS - TRANSPORT (XPORT) FORMAT." -- + TRANSPORT (XPORT) FORMAT." + -- Unless otherwise noted, the contents of this package are (c) 2007 by Random Technologies LLC - <http://random-technologies-llc.com> -- + <http://random-technologies-llc.com> + -- This creation of this package was funded by Metrum Institute <http://metruminstitute.org>. Maintainer: Gregory R. Warnes <gr...@ra...> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2007-08-14 19:14:15
|
Revision: 1141 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1141&view=rev Author: warnes Date: 2007-08-14 12:14:14 -0700 (Tue, 14 Aug 2007) Log Message: ----------- Correct error in balloonplot when z contains NA values. Modified Paths: -------------- trunk/gplots/R/balloonplot.R Modified: trunk/gplots/R/balloonplot.R =================================================================== --- trunk/gplots/R/balloonplot.R 2007-08-14 18:48:36 UTC (rev 1140) +++ trunk/gplots/R/balloonplot.R 2007-08-14 19:14:14 UTC (rev 1141) @@ -75,7 +75,7 @@ scale.method <- match.arg(scale.method) - if( any(z < 0 ) ) + if( any(z < 0, na.rm=TRUE ) ) warning("z value(s) below zero detected.", " No balloons will be displayed for these cells.") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2007-08-14 18:48:39
|
Revision: 1140 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1140&view=rev Author: warnes Date: 2007-08-14 11:48:36 -0700 (Tue, 14 Aug 2007) Log Message: ----------- Augment balloonplot() with control of character size and color for text and label items Modified Paths: -------------- trunk/gplots/R/balloonplot.R trunk/gplots/man/balloonplot.Rd Modified: trunk/gplots/R/balloonplot.R =================================================================== --- trunk/gplots/R/balloonplot.R 2007-08-14 18:11:33 UTC (rev 1139) +++ trunk/gplots/R/balloonplot.R 2007-08-14 18:48:36 UTC (rev 1140) @@ -31,9 +31,13 @@ dotsize=2/max(strwidth(19),strheight(19)), dotchar=19, dotcolor="skyblue", + text.size=1, + text.color=par("fg"), main, label=TRUE, label.digits=2, + label.size=1, + label.color=par("fg"), scale.method=c("volume","diameter"), colsrt=par("srt"), rowsrt=par("srt"), @@ -146,7 +150,7 @@ #### ## Function to scale circles to fill the containing box #### - scale <- function(X, min=0, max=16, scale.method) + myscale <- function(X, min=0, max=16, scale.method) { if(scale.method=="volume") { @@ -154,7 +158,12 @@ X <- sqrt(X) } - X <- min + (X/max(X, na.rm=TRUE) * (max - min) ) + # put min to 0 + X <- (X-min(X, na.rm=TRUE)) + # put max to 1 + X <- X / max(X, na.rm=TRUE ) + # now to [min,max] + X <- min + X * (max - min) cin.x <- par("cin")[1] cin.y <- par("cin")[2] if(cin.x < cin.y) X <- X * cin.x/cin.y @@ -205,7 +214,7 @@ plot(x=nlabels.y*rowmar+0.25 + as.numeric(ztab$x) - 1, y=nlevels(y) - as.numeric(ztab$y) + 1, - cex=scale(ztab$z, max=dotsize, scale.method=scale.method), + cex=myscale(ztab$z, max=dotsize, scale.method=scale.method), pch=dotchar, # plot character col=as.character(ztab$dotcolor), # dot color xlab="", @@ -237,7 +246,9 @@ labels=format(c(sumz, rowsumz), digits=label.digits)[-1], font=1, cex=par("cex")*0.75, - adj=c(0.5,0.0) + adj=c(0.5,0.0), + col=text.color, + cex=text.size ) ## row totals @@ -249,7 +260,9 @@ labels=rowlabs, font=1, cex=par("cex")*0.75, - adj=c(1.0,0.5) + adj=c(1.0,0.5), + col=text.color, + cex=text.size ) ## overall total @@ -259,7 +272,9 @@ labels=sumz, font=1, cex=par("cex")*0.75, - adj=c(1.0,0.0) + adj=c(1.0,0.0), + col=text.color, + cex=text.size ) } @@ -331,7 +346,9 @@ y= y, labels=undupe(xlabs[,i]), srt=colsrt, - font=1 + font=1, + col=text.color, + cex=text.size ) } @@ -345,7 +362,9 @@ x= (i-0.5)*rowmar-0.5, labels=undupe(ylabs[,i]), srt=rowsrt, - font=1 + font=1, + col=text.color, + cex=text.size ) } @@ -359,7 +378,9 @@ labels=ynames, srt=colsrt, font=2, - adj=c(0.5,0.0) + adj=c(0.5,0.0), + col=text.color, + cex=text.size ) else text( @@ -368,7 +389,9 @@ labels=ylab, srt=colsrt, font=2, - adj=c(0.5,0.0) + adj=c(0.5,0.0), + col=text.color, + cex=text.size ) #### @@ -381,7 +404,9 @@ labels=xnames, srt=colsrt, font=2, - adj=c(1,0.5) + adj=c(1,0.5), + col=text.color, + cex=text.size ) else text( @@ -390,7 +415,9 @@ labels=xlab, srt=colsrt, font=2, - adj=c(1,0.5) + adj=c(1,0.5), + col=text.color, + cex=text.size ) ### @@ -426,9 +453,10 @@ text(x=as.numeric(ztab$x[indiv])+ nlabels.y*rowmar - 0.75, # as.numeric give numeric values y=ny - as.numeric(ztab$y[indiv]) + 1, labels=format(ztab$z[indiv], digits=label.digits), # label value - col="black", # text color font=2, - adj=c(0.5,0.5) + adj=c(0.5,0.5), + col=label.color, + cex=label.size ) } # put a nice title Modified: trunk/gplots/man/balloonplot.Rd =================================================================== --- trunk/gplots/man/balloonplot.Rd 2007-08-14 18:11:33 UTC (rev 1139) +++ trunk/gplots/man/balloonplot.Rd 2007-08-14 18:48:36 UTC (rev 1140) @@ -18,9 +18,13 @@ dotsize=2/max(strwidth(19),strheight(19)), dotchar=19, dotcolor="skyblue", + text.size=1, + text.color=par("fg"), main, label=TRUE, label.digits=2, + label.size=1, + label.color=par("fg"), scale.method=c("volume","diameter"), colsrt=par("srt"), rowsrt=par("srt"), @@ -54,10 +58,13 @@ page for the points function for symbol codes.} \item{dotcolor}{Scalar or vector specifying the color(s) of the dots in the plot.} + \item{text.size, text.color}{Character size and color for row and + column headers} \item{main}{Plot title text.} \item{label}{Boolean flag indicating whether the actual value of the elements should be shown on the plot.} \item{label.digits}{Number of digits used in formatting value labels.} + \item{label.size, label.color}{ Character size and color for value labels.} \item{scale.method}{Method of scaling the sizes of the dot, either "volume" or "diameter". See below.} \item{rowsrt, colsrt}{Angle of rotation for row and column labels.} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |