Skip to content

Commit

Permalink
version 1.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Brown authored and gaborcsardi committed Nov 29, 2009
1 parent 4c75c0a commit b3a5400
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 74 deletions.
26 changes: 26 additions & 0 deletions ChangeLog
@@ -1,3 +1,29 @@
2009-11-29 Version 1.10.0 (cbrown)
- R/set.R
+ Fixed problem pointed out by Denise Maudlin from blog.opendatagroup.com
key <- 'one'
ikey <- 'two'
val <- 'three'
info <- hash()
info[key] <- hash( keys=c(ikey), values=c(val) )
Error in get(make.keys(i), x@.Data) : object ‘1′ not found
Solution is to check if only one key is provided than the values are
are the value vector.
- tests/set.r
+ Added test for adding hashes as values.
- Class-hash.R
+ [[-method: verifies if argument is a previously assigned key. If not,
method returns NULL with a warning.
NULL with a warning.
+ $-method: verifies if argument is a previously assigned key. If not,
method returns NULL with a warning.

2009-11-11 (cbrown)
- R/zzz.R
+ Fixed logo
- R/invert.R
+ Made better generic for use with formula tools

2009-11-04 Version 1.0.3 (cbrown)
+ Fixed dependency of R-2.9.0

Expand Down
8 changes: 4 additions & 4 deletions DESCRIPTION
@@ -1,8 +1,8 @@
Package: hash
Type: Package
Title: Implements hash/associated arrays/dictionaries
Version: 1.0.3
Date: 2009-11-04
Version: 1.10.0
Date: 2009-11-29
Author: Christopher Brown
Maintainer: Christopher Brown <cbrown@opendatagroup.com>
Depends: R (>= 2.9.0), methods
Expand All @@ -12,6 +12,6 @@ Description: This package implements a data structure similar to hashes
License: LGPL (>= 2)
URL: http://www.opendatagroup.com, http://blog.opendatagroup.com
LazyLoad: yes
Packaged: 2009-11-04 20:00:38 UTC; cbrown
Packaged: 2009-11-30 02:23:58 UTC; cbrown
Repository: CRAN
Date/Publication: 2009-11-05 12:34:57
Date/Publication: 2009-11-30 15:25:02
71 changes: 27 additions & 44 deletions R/Class-hash.R
Expand Up @@ -47,28 +47,14 @@ setClass(
# ---------------------------------------------------------------------
# getGeneric("[<-")

setReplaceMethod(
"[" ,
signature(
x = "hash" ,
i = "ANY" ,
j = "missing" ,
value = "ANY"
) ,
setReplaceMethod( '[', c(x ="hash", i="ANY" ,j="missing", value="ANY") ,
function( x, i, ..., value ) {
.set( x, i, value, ... )
return( x )
}
)

setReplaceMethod(
"[" ,
signature(
x = "hash" ,
i = "ANY" ,
j = "missing" ,
value = "NULL"
) ,
setReplaceMethod( '[', c(x="hash", i="ANY", j="missing", value="NULL") ,
function( x, i, ..., value ) {
del( i, x )
return( x )
Expand All @@ -88,23 +74,21 @@ setReplaceMethod(
#
# ---------------------------------------------------------------------

setMethod(
"$" ,
signature( "hash", "ANY" ) ,
setMethod( '$' , c( "hash", "ANY" ) ,
function( x, name ) {
key <- make.keys(name)
if( ! key %in% keys(x) ) {
cat( "key:", key, "not found in hash:", substitute(x), "\n" )
return(NULL)
} else {
return( get( key, x@.Data ) )
}

get( make.keys( name ), x@.Data )
}
)


setReplaceMethod(
"$",
signature=signature(
x="hash",
name="ANY",
value="ANY"
),
setReplaceMethod( '$', c(x="hash", name="ANY", value="ANY"),
function(x, name, value) {
assign( name, value, envir = x@.Data )
x
Expand All @@ -113,13 +97,7 @@ setReplaceMethod(

# CASE: NULL value
# When assign a null values to a hash the key is deleted.
setReplaceMethod(
"$",
signature=signature(
x="hash",
name="ANY",
value="NULL"
),
setReplaceMethod( '$', c( x="hash",name="ANY",value="NULL"),
function(x, name, value) {
del(name,x)
x
Expand All @@ -130,30 +108,35 @@ setReplaceMethod(
# ---------------------------------------------------------------------
# [[
# ---------------------------------------------------------------------
setMethod(
"[[",
signature( x="hash", i="ANY", j="missing" ) ,
setMethod( '[[', signature( x="hash", i="ANY", j="missing" ) ,
function(x,i, ...) {
if( length(i) != 1 )
stop( "Can only one hash value with [[. Several keys were provided" )
get( make.keys(i), x@.Data )

key <- make.keys(i)
if( ! key %in% keys(x) ) {

cat( "key:", key, "not found in hash:", substitute(x), "\n" )
return( NULL )

} else {

return( get( key, x@.Data ) )

}
# sapply( make.keys(i), function(k) get(k,x@.Data), ... )
}
)

setReplaceMethod(
"[[",
signature( x="hash", i="ANY", j="missing", value="ANY" ) ,
setReplaceMethod( '[[', c(x="hash", i="ANY", j="missing", value="ANY") ,
function(x,i,value) {
.set( x, i, value )
return( x )
}
)

# CASE: value=NULL
setReplaceMethod(
"[[",
signature( x="hash", i="ANY", j="missing", value="NULL" ) ,
setReplaceMethod( '[[', c(x="hash", i="ANY", j="missing", value="NULL") ,
function(x,i,value) {
# .set( x, i, value )
del( i, x )
Expand Down
Empty file modified R/del.R 100755 → 100644
Empty file.
Empty file modified R/format.R 100755 → 100644
Empty file.
Empty file modified R/get.R 100755 → 100644
Empty file.
Empty file modified R/has-key.R 100755 → 100644
Empty file.
6 changes: 2 additions & 4 deletions R/invert.R 100755 → 100644
Expand Up @@ -5,9 +5,7 @@

setGeneric( "invert", function(x) standardGeneric( "invert" ) )

setMethod(
"invert" ,
"hash" ,
setMethod( 'invert', 'hash',
function(x) {
h <- hash()
for( k in keys(x) ) {
Expand All @@ -23,7 +21,7 @@ setMethod(
)

# h <- hash( a=1, b=1:2, c=1:3 )
# invert.hash(h)
# invert(h)

inverted.hash <- function(...) invert( hash(...) )

Expand Down
Empty file modified R/length.R 100755 → 100644
Empty file.
8 changes: 7 additions & 1 deletion R/set.R
Expand Up @@ -68,7 +68,13 @@
}


if( length( keys ) == length( values ) ) {
# ASSIGNMENT:

if( length(keys) == 1 ) {

assign( keys, values, envir = hash@.Data )

} else if( length( keys ) == length( values ) ) {

for( i in 1:length(keys) )
assign( keys[[i]], values[[i]], envir = hash@.Data )
Expand Down
Empty file modified R/values.R 100755 → 100644
Empty file.
10 changes: 5 additions & 5 deletions R/zzz.R 100755 → 100644
Expand Up @@ -7,11 +7,11 @@

cat(
" _ _ ",
" ___ _ __ ___ _ __ __| | __ _| |_ __ _ ",
" / _ \\| '_ \\ / _ \\ '_ \\ / _` |/ _' | __/ _' |",
"| (_) | |_) | __/ | | | (_| | (_| | || (_| |",
' \\___/| .__/ \\___|_| |_|\\__,_|\\__,_|\\__\\__,_|',
" |_| http://www.opendatagroup.com \n",
" ___ _ __ ___ _ __ __| | __ _| |_ __ _ ",
" / _ \\| '_ \\ / _ \\ '_ \\ / _` |/ _' | __/ _' |",
"| (_) | |_) | __/ | | | (_| | (_| | || (_| |",
" \\___/| .__/ \\___|_| |_|\\__,_|\\__,_|\\__\\__,_|",
" |_| http://www.opendatagroup.com\n",
sep="\n"
)

Expand Down
18 changes: 9 additions & 9 deletions man/hash-accessors.Rd
Expand Up @@ -26,26 +26,26 @@
\details{
These are the hash accessor methods. They closely follow an R style.

\code{$} is a single value look-up operator. It returns the value for the
supplied key. The key name must be literal and will not be interpreted.
\code{$} is a look-up operator for a single key. The key is coerced to valid
hash key via \code{\link{make.keys}} returns the corresponding value. The
key name must be literal it is not interpreted.

\code{[[} is the look-up, extraction operator. It returns the values of
one keys. The key names will be interpreted. If you wish to extract
multiple keys, use the \code{[} accessor.

a single key. The key names will be interpreted and coerced to a valid hash
key via \code{\link{make.keys}}.
\code{[} is a subseting operator. It returns a (sub) hash with the specified
keys. All other keys are removed.
keys. All other keys are removed. Key names are coerced via \code{\link{make.keys}}

}

\value{

\$ returns the value for the supplied key.
\$ and [[ return the value for the supplied argument. If a key does not
match an existing key, then \code{NULL} is returned with a warning.

[ returns a hash slice, a sub hash with only the defined keys.

[[ returns a one or more values.

}

\author{ Christopher Brown }
Expand Down
2 changes: 1 addition & 1 deletion man/hash-class.Rd
Expand Up @@ -69,7 +69,7 @@
}

\seealso{
See also as \code{\link{environment}}.
\code{\link{hash-accessors}}, \code{\link{environment}}.
}

\examples{
Expand Down
4 changes: 2 additions & 2 deletions man/hash-package.Rd
Expand Up @@ -18,8 +18,8 @@
\tabular{ll}{
Package: \tab hash\cr
Type: \tab Package\cr
Version: \tab 1.0.3\cr
Date: \tab 2009-11-04\cr
Version: \tab 1.10.0\cr
Date: \tab 2009-11-29\cr
License: \tab LGPL 2+\cr
LazyLoad: \tab yes\cr
Depends: \tab R (>= 2.9.0), methods\cr
Expand Down
6 changes: 3 additions & 3 deletions man/invert.Rd 100755 → 100644
Expand Up @@ -17,12 +17,12 @@ inverted.hash(...)
}
\arguments{
\item{x}{ A \code{\link{hash}} object }
\item{...}{ Arguments passed to \code{\link{hash}} }
\item{...}{ Arguments passed to the \code{\link{hash}} function. }
}
\details{

For \code{invert}, keys and value elements swtich. Each element of the \code{values(x)}
is coerced to a key. The value is the associated key.
For \code{invert}, keys and value elements switch. Each element of the
\code{values(x)} is coerced to a key. The value becomes the associated key.

For \code{inverted.hash}, a hash is created than inverted. It is defined as:

Expand Down
10 changes: 9 additions & 1 deletion tests/set.R
Expand Up @@ -10,9 +10,17 @@ h <- hash()
.set( h, 1:5, 1:5 )
.set( h, letters, 12 )


# SET: key-hash pair added in version 1.0.4
.set( h, "ha", hash( a=1, b=2 ) )
class( h[["ha"]] ) == "hash"


# SET: data.frame
.set( h, "df", data.frame( a=1:10, b=11:20) )
class( h[["df"]] ) == "data.frame"

# SET: list
.set( h, "li", list( a=1, b=1:5, c=letters[1:3] ) )
class( h[["li"]] ) == "list"

# SET: environment

0 comments on commit b3a5400

Please sign in to comment.