Learn R Programming

sos (version 2.1-8)

unionFindFn: Combine findFn Objects

Description

Combines to findFn objects into a new findFn object with only one row for any help page duplicated between the two. unionFindFn removes duplicate entries. intersectFindFn keeps only the duplicates.

Usage

unionFindFn(e1, e2, sortby=NULL)
intersectFindFn(e1, e2, sortby=NULL)

# S3 method for findFn Ops(e1,e2) # This supports "|" for "unionFindFn" # and "&" for "intersectFindFn".

Value

an object with class

c('findFn', 'data.frame') as returned by sortFindFn and findFn.

Arguments

e1, e2

objects of class findFn.

sortby

Optional sortby argument used by sortFindFn and findFn. Default is the sortby argument in attr(e1, 'call').

Author

Spencer Graves and Romain Francois

Details

1. e12 <- rbind(e1, e2)

2. For any (Package, Function) appearing in both e1 and e2, the row with the largest Score is retained and the other is deleted.

3. Apply sortFindFn to the rebuild the summary and sort the result as desired.

4. attr(e12, 'matches') <- c(attr(e1, 'matches'), attr(e2, 'matches'))

See Also

findFn sortFindFn

Examples

Run this code
des1 <- findFn('differential equations', 1)
de1 <- findFn('differential equation', 1)
# each retrieves 1 page of 20 hits
# but not the same 20

de.s <- unionFindFn(des1, de1)
# combines the two, eliminating duplicates.

# or the sorter version:
de.s. <- des1 | de1
stopifnot(
all.equal(de.s, de.s.)
)

# \dontshow{
# union with no data
de0 <- unionFindFn(des1[numeric(0), ], de1[numeric(0), ])
# }

# Keep only the common entries.
de2 <- intersectFindFn(des1, de1)
de2. <- des1 & de1
stopifnot(
all.equal(de2, de2.)
)

# summary and print still work with the combined object.
summary(de.s)
if(!CRAN()){
  de.s
}

summary(de2)
if(!CRAN()){
  de2
}

# \dontshow{
# The following gave an error;  now fixed 2009.05.12
x <- try(findFn("spline", maxPages = 1, quiet = TRUE))
y <- try(findFn("winbugs", maxPages = 1, quiet = TRUE))
if(!(inherits(x, 'try-error') ||
     inherits(y, 'try-error'))){
    xy <- intersectFindFn( x, y )
}
# }

Run the code above in your browser using DataLab