Skip to content

Commit

Permalink
fixes Stack and List exports; passed R check
Browse files Browse the repository at this point in the history
  • Loading branch information
sizrailev committed Sep 1, 2022
1 parent d8e2c37 commit 8cf7894
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 33 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tictoc
Title: Functions for Timing R Scripts, as Well as Implementations of "Stack"
and "List" Structures
Version: 1.0.2
Version: 1.1
Author: Sergei Izrailev
Maintainer: Sergei Izrailev <sizrailev@jabiruventures.com>
Description: Code execution timing functions 'tic' and 'toc' that
Expand Down
27 changes: 27 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,42 @@

S3method(as.List,default)
S3method(as.Stack,default)
S3method(as.list,List)
S3method(as.vector,Stack)
S3method(clear,List)
S3method(clear,Stack)
S3method(clear,default)
S3method(first,List)
S3method(first,Stack)
S3method(first,default)
S3method(last,List)
S3method(last,Stack)
S3method(last,default)
S3method(pop,List)
S3method(pop,Stack)
S3method(pop,default)
S3method(print,List)
S3method(print,Stack)
S3method(push,List)
S3method(push,Stack)
S3method(push,default)
S3method(shift,List)
S3method(shift,Stack)
S3method(shift,default)
S3method(size,List)
S3method(size,Stack)
S3method(size,default)
export(List)
export(Stack)
export(as.List)
export(as.Stack)
export(clear)
export(first)
export(last)
export(pop)
export(push)
export(shift)
export(size)
export(tic)
export(tic.clear)
export(tic.clearlog)
Expand Down
4 changes: 2 additions & 2 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Version 1.0.2
Version 1.1
- Exporting Stack and List.
- Updated documentation formatting.
- Updated maintainer contact and package location - this didn't work in 1.0.1 submission.
- Updated maintainer contact and package location - this didn't work in the v1.0.1 submission.
Version 1.0.1
- Updated maintainer contact and package location.
Version 1.0
Expand Down
70 changes: 56 additions & 14 deletions R/stack.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@
#' @param x A Stack or List object.
#' @param value Value to append.
#' @param s A structure to be converted to a Stack or List.
#' @name Stack
#' @name Stack and List
#' @aliases Stack List push.default pop.default clear.default shift.default first.default last.default size.default as.Stack.default as.List.default
#' @rdname Stack
#' @export
#' @method push default
push <- function(x, value) UseMethod("push") # append an element

#-------------------------------------------------------------------------------
Expand All @@ -47,7 +46,6 @@ push <- function(x, value) UseMethod("push") # append an element
#' \code{pop} - Remove and return the last element.
#' @rdname Stack
#' @export
#' @method pop default
pop <- function(x) UseMethod("pop") # pop the last element

#-------------------------------------------------------------------------------
Expand All @@ -56,7 +54,6 @@ pop <- function(x) UseMethod("pop") # pop the last element
#' \code{clear} - Remove all elements.
#' @rdname Stack
#' @export
#' @method clear default
clear <- function(x) UseMethod("clear")

#-------------------------------------------------------------------------------
Expand All @@ -65,7 +62,6 @@ clear <- function(x) UseMethod("clear")
#' \code{shift} - Remove and return the first element.
#' @rdname Stack
#' @export
#' @method shift default
shift <- function(x) UseMethod("shift") # pop the first element

#-------------------------------------------------------------------------------
Expand All @@ -74,7 +70,6 @@ shift <- function(x) UseMethod("shift") # pop the first element
#' \code{first} - Return the first element.
#' @rdname Stack
#' @export
#' @method first default
first <- function(x) UseMethod("first") # return the first element

#-------------------------------------------------------------------------------
Expand All @@ -83,7 +78,6 @@ first <- function(x) UseMethod("first") # return the first element
#' \code{last} - Return the last element.
#' @rdname Stack
#' @export
#' @method last default
last <- function(x) UseMethod("last") # return the last element

#-------------------------------------------------------------------------------
Expand All @@ -92,7 +86,6 @@ last <- function(x) UseMethod("last") # return the last element
#' \code{size} - Return the number of elements.
#' @rdname Stack
#' @export
#' @method size default
size <- function(x) UseMethod("size") # return the number of elements

#-------------------------------------------------------------------------------
Expand All @@ -101,8 +94,9 @@ size <- function(x) UseMethod("size") # return the number of elements
#' \code{as.Stack} - Creates a new Stack from (typically, vector) \code{s}.
#' @rdname Stack
#' @export
#' @method as.Stack default
as.Stack <- function(s) UseMethod("as.Stack")

#' @export
as.Stack.default <- function(s)
{
stack <- Stack()
Expand All @@ -114,8 +108,9 @@ as.Stack.default <- function(s)
#' \code{as.List} - Creates a new List from (typically, list) \code{s}.
#' @rdname Stack
#' @export
#' @method as.List default
as.List <- function(s) UseMethod("as.List")

#' @export
as.List.default <- function(s)
{
lst <- List()
Expand All @@ -128,23 +123,57 @@ as.List.default <- function(s)
#' @aliases push pop clear shift first last size
#' @export
push.default <- function(x, value) stop(gettextf("Unknown class for '%s'.", deparse(substitute(x))))

#' @export
pop.default <- function(x) stop(gettextf("Unknown class for '%s'.", deparse(substitute(x))))

#' @export
clear.default <- function(x) stop(gettextf("Unknown class for '%s'.", deparse(substitute(x))))

#' @export
shift.default <- function(x) stop(gettextf("Unknown class for '%s'.", deparse(substitute(x))))

#' @export
first.default <- function(x) stop(gettextf("Unknown class for '%s'.", deparse(substitute(x))))

#' @export
last.default <- function(x) stop(gettextf("Unknown class for '%s'.", deparse(substitute(x))))

#' @export
size.default <- function(x) stop(gettextf("Unknown class for '%s'.", deparse(substitute(x))))

#' @export
push.Stack <- function(x, value) x$push(value)

#' @export
pop.Stack <- function(x) x$pop()

#' @export
clear.Stack <- function(x) x$clear()

#' @export
shift.Stack <- function(x) x$shift()

#' @export
first.Stack <- function(x) x$first()

#' @export
last.Stack <- function(x) x$last()

#' @export
size.Stack <- function(x) x$size()

#' @export
as.vector.Stack <- function(x, mode = "any") as.vector(x$.Data)
print.Stack <- function(x) print(x$.Data)
as.list.List <- function(x) as.list(x$.Data)
print.List <- function(x) print(x$.Data)

#' @export
print.Stack <- function(x, ...) print(x$.Data)

#' @export
as.list.List <- function(x, ...) as.list(x$.Data)

#' @export
print.List <- function(x, ...) print(x$.Data)

#-------------------------------------------------------------------------------

Expand All @@ -162,7 +191,7 @@ Stack <- function()
stack$push <- function(x)
{
if (is.list(x)) stop("Can't push a list on a stack")
.Data <<- c(.Data,x)
.Data <<- c(.Data, x)
}

stack$pop <- function()
Expand Down Expand Up @@ -202,12 +231,25 @@ Stack <- function()
#------------------------------------------------------------------------------

# LIST - keeps a list of items with append and clear operations
#' @export
push.List <- function(x, value, ...) x$push(value)

#' @export
pop.List <- function(x) x$pop()

#' @export
clear.List <- function(x) x$clear()

#' @export
shift.List <- function(x) x$shift()

#' @export
first.List <- function(x) x$first()

#' @export
last.List <- function(x) x$last()

#' @export
size.List <- function(x) x$size()

#' @description
Expand Down
11 changes: 6 additions & 5 deletions R/tictoc.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# http://stackoverflow.com/questions/1716012/stopwatch-function-in-r
# by http://stackoverflow.com/users/134830/richie-cotton
# stackoverflow license: http://creativecommons.org/licenses/by-sa/2.5/
# It was changed to globalenv in this package.
# It was changed to use globalenv in this package.
#
# tic <- function(gcFirst = TRUE, type=c("elapsed", "user.self", "sys.self"))
# {
Expand All @@ -40,9 +40,9 @@
#
# toc <- function()
# {
# type <- get(".type", envir=globalenv())
# type <- get(".type", envir=baseenv())
# toc <- proc.time()[type]
# tic <- get(".tic", envir=globalenv())
# tic <- get(".tic", envir=baseenv())
# print(toc - tic)
# invisible(toc)
# }
Expand Down Expand Up @@ -239,8 +239,9 @@ toc <- function(log = FALSE, quiet = FALSE, func.toc = toc.outmsg, ...)
#' @rdname tic
toc.outmsg <- function(tic, toc, msg)
{
if (is.null(msg) || is.na(msg) || length(msg) == 0) outmsg <- paste(round(toc - tic, 3), " sec elapsed", sep="")
else outmsg <- paste(msg, ": ", round(toc - tic, 3), " sec elapsed", sep="")
if (is.null(msg) || is.na(msg) || length(msg) == 0) outmsg <- paste0(round(toc - tic, 3), " sec elapsed")
else outmsg <- paste0(msg, ": ", round(toc - tic, 3), " sec elapsed")
outmsg
}

#-------------------------------------------------------------------------------
Expand Down
Binary file modified inst/tictoc_1.0.2.pdf
Binary file not shown.
Binary file added inst/tictoc_1.1.pdf
Binary file not shown.
23 changes: 12 additions & 11 deletions man/Stack.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8cf7894

Please sign in to comment.