Skip to content

Commit

Permalink
Sync with 2.18.0 on CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
Arni Magnusson committed Mar 27, 2020
1 parent 4eac346 commit aa6551e
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 264 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Description: Various R programming tools for data manipulation, including:
Depends: R (>= 2.3.0)
SystemRequirements: perl (>= 5.10.0)
Imports: gtools, stats, methods, utils
Version: 2.17.0
Date: 2015-07-02
Version: 2.18.0
Date: 2017-06-05
Author: Gregory R. Warnes, Ben Bolker, Gregor Gorjanc, Gabor
Grothendieck, Ales Korosec, Thomas Lumley, Don MacQueen, Arni
Magnusson, Jim Rogers, and others
Expand Down
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export(
trimSum,
unmatrix,
update.list,
update.data.frame,
#update.data.frame,
upperTriangle,
"upperTriangle<-",
wideByFactor,
Expand Down Expand Up @@ -171,4 +171,4 @@ S3method(right, matrix)

# update methods for list, data.frame
S3method(update, list)
S3method(update, data.frame)
#S3method(update, data.frame)
8 changes: 6 additions & 2 deletions R/startsWith.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
startsWith <- function(str, pattern, trim=FALSE, ignore.case=FALSE)
{
if(trim) str <- trim(str)

if(ignore.case)
{
str <- toupper(str)
pattern <- toupper(pattern)
}
substr(str,start=1,stop=nchar(pattern))==pattern
}

#substr(str,start=1,stop=nchar(pattern))==pattern

base::startsWith(str, pattern)
}
81 changes: 48 additions & 33 deletions R/update.data.frame.R
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
# This function replace rows in 'x' by corresponding rows in 'y' the have
# the same value for 'by'
update.data.frame <- function(x, y, by, by.x=by, by.y=by, append=TRUE, verbose=TRUE, ...)
{
retval <- x
x.by <- x[[by.x]]
y.by <- y[[by.y]]

matches.x <- match(y.by, x.by)
matches.y <- which(!is.na(matches.x))
nomatch.y <- which(is.na(matches.x))
matches.x <- matches.x[!is.na(matches.x)]

if(length(matches.x)>0)
retval[matches.x, ] <- y[matches.y,]

if(length(nomatch.y) && append)
retval <- rbind(retval, y[nomatch.y,])

if(verbose)
{
cat("\n")
cat("Number of rows in x :", nrow(x), "\n")
cat("Number of rows in y :", nrow(y), "\n")
cat("\n")
cat("Number of rows replaced :", length(matches.x), "\n")
cat("Number of rows appended :", length(nomatch.y), "\n")
cat("\n")
cat("Number of rows in result:", nrow(retval), "\n")
cat("\n")
}
retval
}
# # This function replace rows in 'object' by corresponding rows in 'new' that have
# # the same value for 'by'
# update.data.frame <- function(object,
# new,
# by,
# by.object=by,
# by.new=by,
# append=TRUE,
# verbose=TRUE,
# ...)
# {
# retval <- object
#
# if(length(by.object)>1)
# stop("'by.object' can specify at most one column")
#
# if(length(by.new)>1)
# stop("'by.new' can specify at most one column")
#
#
# object.by <- object[[by.object]]
# new.by <- new [[by.new ]]
#
# matches.object <- match(new.by, object.by)
# matches.new <- which(!is.na(matches.object))
# nomatch.new <- which(is.na(matches.object))
# matches.object <- matches.object[!is.na(matches.object)]
#
# if(length(matches.object)>0)
# retval[matches.object, ] <- new[matches.new,]
#
# if(length(nomatch.new) && append)
# retval <- rbind(retval, new[nomatch.new,])
#
# if(verbose)
# {
# cat("\n")
# cat("Number of rows in object:", nrow(object), "\n")
# cat("Number of rows in new :", nrow(new), "\n")
# cat("\n")
# cat("Number of rows replaced :", length(matches.object), "\n")
# cat("Number of rows appended :", length(nomatch.new), "\n")
# cat("\n")
# cat("Number of rows in result:", nrow(retval), "\n")
# cat("\n")
# }
# retval
# }
8 changes: 6 additions & 2 deletions R/update.list.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
## this function updates the elements of list 'object' to contain all of the elements
## of 'new', overwriting elements with the same name, and (optionally) copying unnamed
## elements.
update.list <- function(object, new, unnamed=FALSE, ...)
update.list <- function(object,
new,
unnamed=FALSE,
...)
{
retval <- object

Expand All @@ -17,4 +20,5 @@ update.list <- function(object, new, unnamed=FALSE, ...)
}

retval
}
}

Loading

0 comments on commit aa6551e

Please sign in to comment.