Skip to content

Commit b267c22

Browse files
author
warnes
committed
Rename 'trunk' to 'pkg' for compatibility with R-forge
0 parents  commit b267c22

File tree

198 files changed

+52848
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+52848
-0
lines changed

.Rinstignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
doc/.*\.tex$
2+
doc/.*\.sty$
3+
doc/.*\.dtx$
4+
\.svn

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
inst/ChangeLog

DESCRIPTION

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Package: gdata
2+
Title: Various R Programming Tools for Data Manipulation
3+
Description: Various R programming tools for data manipulation, including:
4+
- medical unit conversions ('ConvertMedUnits', 'MedUnits'),
5+
- combining objects ('bindData', 'cbindX', 'combine', 'interleave'),
6+
- character vector operations ('centerText', 'startsWith', 'trim'),
7+
- factor manipulation ('levels', 'reorder.factor', 'mapLevels'),
8+
- obtaining information about R objects ('object.size', 'elem', 'env',
9+
'humanReadable', 'is.what', 'll', 'keep', 'ls.funs',
10+
'Args','nPairs', 'nobs'),
11+
- manipulating MS-Excel formatted files ('read.xls',
12+
'installXLSXsupport', 'sheetCount', 'xlsFormats'),
13+
- generating fixed-width format files ('write.fwf'),
14+
- extricating components of date & time objects ('getYear', 'getMonth',
15+
'getDay', 'getHour', 'getMin', 'getSec'),
16+
- operations on columns of data frames ('matchcols', 'rename.vars'),
17+
- matrix operations ('unmatrix', 'upperTriangle', 'lowerTriangle'),
18+
- operations on vectors ('case', 'unknownToNA', 'duplicated2', 'trimSum'),
19+
- operations on data frames ('frameApply', 'wideByFactor'),
20+
- value of last evaluated expression ('ans'), and
21+
- wrapper for 'sample' that ensures consistent behavior for both
22+
scalar and vector arguments ('resample').
23+
Depends: R (>= 2.3.0)
24+
SystemRequirements: perl (>= 5.10.0)
25+
Imports: gtools
26+
Version: 2.16.1
27+
Date: 2015-04-28
28+
Author: Gregory R. Warnes, Ben Bolker, Gregor Gorjanc, Gabor
29+
Grothendieck, Ales Korosec, Thomas Lumley, Don MacQueen, Arni
30+
Magnusson, Jim Rogers, and others
31+
Maintainer: Gregory R. Warnes <greg@warnes.net>
32+
License: GPL-2
33+
NeedsCompilation: no
34+
Suggests: RUnit

INSTALL

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
Windows
3+
=======
4+
5+
The instructions below relate to Windows only and are not relevant to other
6+
platforms.
7+
8+
On Windows, the perl based routines (read.xls, xls2sep, xls2csv, xls2tab,
9+
xls2tsv, sheetNames, sheetCount) will work with ActiveState perl but not with
10+
Rtools perl.
11+
12+
If you have ActiveState perl installed and the pl extension is associated with
13+
it (which the ActiveState installer associates automatically) then read.xls and
14+
other perl based routines in gdata will automatically locate ActiveState perl
15+
if you omit the perl= argument on these commands even if Rtools perl is ahead
16+
of it on your path. e.g.
17+
18+
read.xls("mysheet.xls")
19+
20+
Alternately you can use the perl= argument with a path to ActiveState perl to
21+
ensure it uses the right one. e.g.
22+
23+
read.xls("mysheet.xls", perl = "C:\\Perl\\bin\\perl.exe")
24+
25+
Also ensure that gdata was built with ActiveState Perl and not Rtools perl.
26+
This may require rebuilding gdata yourself like this:
27+
28+
1. Download and install the following (which all have automatic Windows
29+
installers and are therefore very easy to install):
30+
31+
R (you likely already have R so you can likely skip this one)
32+
http://www.r-project.org
33+
34+
Rtools
35+
http://www.murdoch-sutherland.com/Rtools/
36+
37+
ActiveState perl (ActivePerl)
38+
http://www.activestate.com/activeperl/
39+
40+
2. If simply installing gdata in the usual way from within R results in
41+
read.xls and associated perl-based routines not working then re-install
42+
gdata yourself like this:
43+
44+
Download gdata_*.tar.gz from:
45+
http://cran.r-project.org/web/packages/gdata/index.html
46+
47+
and install it at the Windows console (not from within R):
48+
Rcmd INSTALL --build gdata_*.tar.gz
49+
50+
Note: Rcmd is normally found in C:\Program Files\R\R-*\bin and if that
51+
is not on your path the above command should be written:
52+
"C:\Program Files\R\R-*\bin\Rcmd.exe" INSTALL --build gdata_*.tar.gz
53+
54+
where the the path to Rcmd.exe should be replaced with the output of this
55+
R command:
56+
normalizePath(file.path(R.home(), "bin", "Rcmd.exe"))
57+
58+
Note: On Vista and above you may need to run Rcmd as Administrator.
59+
60+
Note: In the above the * in gdata_*.tar.gz should be replaced with the
61+
current version of gdata as found on:
62+
http://cran.r-project.org/web/packages/gdata/index.html
63+

NAMESPACE

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
2+
export(
3+
.onAttach,
4+
ans,
5+
Args,
6+
bindData,
7+
case,
8+
cbindX,
9+
centerText,
10+
combine,
11+
ConvertMedUnits,
12+
drop.levels,
13+
duplicated2,
14+
elem,
15+
env,
16+
first,
17+
frameApply,
18+
installXLSXsupport,
19+
interleave,
20+
is.what,
21+
keep,
22+
last,
23+
left,
24+
ll,
25+
ls.funs,
26+
lowerTriangle,
27+
"lowerTriangle<-",
28+
matchcols,
29+
nobs, # default method now provided by stats package
30+
nPairs,
31+
read.xls,
32+
rename.vars,
33+
remove.vars,
34+
reorder.factor,
35+
resample,
36+
right,
37+
sheetCount,
38+
sheetNames,
39+
startsWith,
40+
trim,
41+
trimSum,
42+
unmatrix,
43+
upperTriangle,
44+
"upperTriangle<-",
45+
wideByFactor,
46+
write.fwf,
47+
xls2csv,
48+
xls2tab,
49+
xls2tsv,
50+
xls2sep,
51+
xlsFormats,
52+
53+
## Object size stuff
54+
object.size, as.object_sizes, is.object_sizes, humanReadable,
55+
56+
## getDateTime stuff
57+
getYear, getMonth, getDay, getHour, getMin, getSec,
58+
59+
## mapLevels stuff
60+
mapLevels, as.levelsMap, as.listLevelsMap, is.levelsMap, is.listLevelsMap, "mapLevels<-",
61+
62+
## unknown stuff
63+
isUnknown, unknownToNA, NAToUnknown
64+
)
65+
66+
importFrom(stats, reorder)
67+
importFrom(stats, nobs)
68+
importFrom(gtools, mixedsort)
69+
70+
S3method(reorder, factor)
71+
72+
S3method(summary, nPairs)
73+
74+
## drop.levels stuff
75+
S3method(drop.levels, default)
76+
S3method(drop.levels, factor)
77+
S3method(drop.levels, list)
78+
S3method(drop.levels, data.frame)
79+
80+
## getDateTime stuff
81+
S3method(getYear, default)
82+
S3method(getYear, Date)
83+
S3method(getYear, POSIXct)
84+
S3method(getYear, POSIXlt)
85+
86+
S3method(getMonth, default)
87+
S3method(getMonth, Date)
88+
S3method(getMonth, POSIXct)
89+
S3method(getMonth, POSIXlt)
90+
91+
S3method(getDay, default)
92+
S3method(getDay, Date)
93+
S3method(getDay, POSIXct)
94+
S3method(getDay, POSIXlt)
95+
96+
S3method(getHour, default)
97+
98+
S3method(getMin, default)
99+
100+
S3method(getSec, default)
101+
102+
## mapLevels stuff
103+
S3method(mapLevels, default)
104+
S3method(mapLevels, character)
105+
S3method(mapLevels, factor)
106+
S3method(mapLevels, list)
107+
S3method(mapLevels, data.frame)
108+
109+
S3method("mapLevels<-", default)
110+
S3method("mapLevels<-", list)
111+
S3method("mapLevels<-", data.frame)
112+
113+
S3method(print, levelsMap)
114+
S3method(print, listLevelsMap)
115+
116+
S3method("[", levelsMap)
117+
S3method("[", listLevelsMap)
118+
119+
S3method(c, levelsMap)
120+
S3method(c, listLevelsMap)
121+
122+
S3method(unique, levelsMap)
123+
S3method(sort, levelsMap)
124+
125+
## nobs stuff
126+
S3method(nobs, data.frame)
127+
S3method(nobs, default)
128+
S3method(nobs, lm) # now provided by stats package
129+
130+
## Object size stuff
131+
S3method(c, object_sizes)
132+
S3method(format, object_sizes)
133+
S3method(print, object_sizes)
134+
135+
## unknown stuff
136+
S3method(isUnknown, default)
137+
S3method(isUnknown, POSIXlt)
138+
S3method(isUnknown, list)
139+
S3method(isUnknown, data.frame)
140+
S3method(isUnknown, matrix)
141+
142+
S3method(unknownToNA, default)
143+
S3method(unknownToNA, factor)
144+
S3method(unknownToNA, list)
145+
S3method(unknownToNA, data.frame)
146+
147+
S3method(NAToUnknown, default)
148+
S3method(NAToUnknown, factor)
149+
S3method(NAToUnknown, list)
150+
S3method(NAToUnknown, data.frame)
151+
152+
## trim stuff
153+
S3method(trim, character)
154+
S3method(trim, default)
155+
S3method(trim, factor)
156+
S3method(trim, list)
157+
S3method(trim, data.frame)
158+
159+
## left, right
160+
S3method(left, data.frame)
161+
S3method(left, matrix)
162+
S3method(right, data.frame)
163+
S3method(right, matrix)

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
inst/NEWS

R/Args.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Args <- function(name, sort=FALSE)
2+
{
3+
a <- formals(get(as.character(substitute(name)), pos=1))
4+
if(is.null(a))
5+
return(NULL)
6+
arg.labels <- names(a)
7+
arg.values <- as.character(a)
8+
char <- sapply(a, is.character)
9+
arg.values[char] <- paste("\"", arg.values[char], "\"", sep="")
10+
11+
if(sort)
12+
{
13+
ord <- order(arg.labels)
14+
if(any(arg.labels == "..."))
15+
ord <- c(ord[-which(arg.labels[ord]=="...")],
16+
which(arg.labels=="..."))
17+
arg.labels <- arg.labels[ord]
18+
arg.values <- arg.values[ord]
19+
}
20+
21+
output <- data.frame(value=I(arg.values), row.names=arg.labels)
22+
print(output, right=FALSE)
23+
24+
invisible(output)
25+
}

R/ConvertMedUnits.R

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
ConvertMedUnits <- function(x, measurement, abbreviation,
2+
to=c("Conventional","SI","US"),
3+
exact=!missing(abbreviation))
4+
{
5+
MedUnits <- NULL ## Define to avoid R CMD check warning
6+
data(MedUnits,package='gdata', envir=environment())
7+
8+
to=match.arg(to)
9+
if(!missing(measurement) && missing(abbreviation))
10+
{
11+
if(exact)
12+
matchUnits <- MedUnits[tolower(MedUnits$Measurement)==
13+
tolower(measurement),]
14+
else
15+
matchUnits <- MedUnits[grep(measurement, MedUnits$Measurement,
16+
ignore.case=TRUE),]
17+
}
18+
else if(missing(measurement) && !missing(abbreviation))
19+
{
20+
if(exact)
21+
matchUnits <- MedUnits[tolower(MedUnits$Abbreviation)==
22+
tolower(abbreviation),]
23+
else
24+
matchUnits <- MedUnits[grep(match, MedUnits$Abbrevation,
25+
ignore.case=TRUE),]
26+
}
27+
else # both missing or both specified
28+
stop("One of `measurement' or `abbreviation' must be specified.")
29+
30+
31+
if(nrow(matchUnits)>1)
32+
stop(
33+
paste("More than one matching row. Please use 'exact=TRUE' ",
34+
"and supply one of these matching strings:",
35+
paste('\t"',matchUnits$Measurement, '"', sep='', collapse="\n\t"),
36+
sep="\n\t"))
37+
else if (nrow(matchUnits)<1)
38+
stop("No match")
39+
40+
if (to %in% c("Convetional", "US"))
41+
{
42+
retval <- x / matchUnits$Conversion
43+
attr(retval,"units") <- matchUnits$ConventionalUnits
44+
}
45+
else
46+
{
47+
retval <- x * matchUnits$Conversion
48+
attr(retval,"units") <- matchUnits$SIUnits
49+
}
50+
retval
51+
}
52+
53+
54+
55+
56+

R/ans.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ans <- function() .Last.value

R/bindData.R

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
### bindData.R
2+
###------------------------------------------------------------------------
3+
### What: Bind two data frames - code
4+
### $Id$
5+
### Time-stamp: <2008-12-30 22:01:00 ggorjan>
6+
###------------------------------------------------------------------------
7+
8+
bindData <- function(x, y, common)
9+
{
10+
## --- Setup ---
11+
if(!is.data.frame(x)) stop("'x' must be a data frame")
12+
if(!is.data.frame(y)) stop("'y' must be a data frame")
13+
14+
## --- New data frame ---
15+
16+
## First add common column and a dataset indicator column
17+
z <- rbind(x[common], y[common])
18+
19+
## Other columns
20+
## - remove common columns in x and y
21+
namesz <- names(z)
22+
otherx <- names(x)
23+
otherx <- otherx[!(otherx %in% namesz)]
24+
othery <- names(y)
25+
othery <- othery[!(othery %in% namesz)]
26+
27+
## - add all other columns but as a set for each input data frame
28+
rx <- nrow(x); cx <- length(otherx)
29+
ry <- nrow(y); cy <- length(othery)
30+
31+
z <- cbind(z, rbind(x[otherx], matrix(rep(NA, times=(ry * cx)), nrow=ry, ncol=cx, dimnames=list(NULL, otherx))))
32+
z <- cbind(z, rbind(matrix(rep(NA, times=(rx * cy)), nrow=rx, ncol=cy, dimnames=list(NULL, othery)), y[othery]))
33+
34+
z
35+
}
36+
37+
###------------------------------------------------------------------------
38+
### bindData.R ends here

0 commit comments

Comments
 (0)