Skip to content

Commit

Permalink
Use @exportS3Method instead of register_s3_method()
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed May 14, 2024
1 parent 1aa0b1a commit 49f96b9
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 78 deletions.
38 changes: 38 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,48 @@ S3method(format,fs_bytes)
S3method(format,fs_perms)
S3method(max,fs_bytes)
S3method(min,fs_bytes)
S3method(pillar::pillar_shaft,fs_bytes)
S3method(pillar::pillar_shaft,fs_path)
S3method(pillar::pillar_shaft,fs_perms)
S3method(pillar::type_sum,fs_bytes)
S3method(pillar::type_sum,fs_path)
S3method(pillar::type_sum,fs_perms)
S3method(print,fs_bytes)
S3method(print,fs_path)
S3method(print,fs_perms)
S3method(sum,fs_bytes)
S3method(testthat::compare,fs_path)
S3method(testthat::compare,fs_perms)
S3method(vctrs::vec_cast,character.fs_path)
S3method(vctrs::vec_cast,character.fs_perms)
S3method(vctrs::vec_cast,double.fs_bytes)
S3method(vctrs::vec_cast,double.fs_perms)
S3method(vctrs::vec_cast,fs_bytes.double)
S3method(vctrs::vec_cast,fs_bytes.fs_bytes)
S3method(vctrs::vec_cast,fs_bytes.integer)
S3method(vctrs::vec_cast,fs_path.character)
S3method(vctrs::vec_cast,fs_path.fs_path)
S3method(vctrs::vec_cast,fs_perms.character)
S3method(vctrs::vec_cast,fs_perms.double)
S3method(vctrs::vec_cast,fs_perms.fs_perms)
S3method(vctrs::vec_cast,fs_perms.integer)
S3method(vctrs::vec_cast,integer.fs_bytes)
S3method(vctrs::vec_cast,integer.fs_perms)
S3method(vctrs::vec_ptype2,character.fs_path)
S3method(vctrs::vec_ptype2,character.fs_perms)
S3method(vctrs::vec_ptype2,double.fs_bytes)
S3method(vctrs::vec_ptype2,double.fs_perms)
S3method(vctrs::vec_ptype2,fs_bytes.double)
S3method(vctrs::vec_ptype2,fs_bytes.fs_bytes)
S3method(vctrs::vec_ptype2,fs_bytes.integer)
S3method(vctrs::vec_ptype2,fs_path.character)
S3method(vctrs::vec_ptype2,fs_path.fs_path)
S3method(vctrs::vec_ptype2,fs_perms.character)
S3method(vctrs::vec_ptype2,fs_perms.double)
S3method(vctrs::vec_ptype2,fs_perms.fs_perms)
S3method(vctrs::vec_ptype2,fs_perms.integer)
S3method(vctrs::vec_ptype2,integer.fs_bytes)
S3method(vctrs::vec_ptype2,integer.fs_perms)
S3method(xtfrm,fs_path)
export("path_ext<-")
export(as_fs_bytes)
Expand Down
14 changes: 12 additions & 2 deletions R/fs_bytes.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,47 +142,57 @@ Ops.fs_bytes <- function (e1, e2) {
NextMethod(.Generic)
}

#' @exportS3Method pillar::pillar_shaft
pillar_shaft.fs_bytes <- function(x, ...) {
pillar::new_pillar_shaft_simple(format.fs_bytes(x), align = "right", ...)
}

#' @exportS3Method pillar::type_sum
type_sum.fs_bytes <- function(x) {
"fs::bytes"
}

# All functions below registered in .onLoad

#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.fs_bytes.fs_bytes <- function(x, y, ...) {
x
}
#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.fs_bytes.double <- function(x, y, ...) {
x
}
#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.double.fs_bytes <- function(x, y, ...) {
y
}

# Note order of class is the opposite as for ptype2
#' @exportS3Method vctrs::vec_cast
vec_cast.fs_bytes.fs_bytes <- function(x, to, ...) {
x
}
#' @exportS3Method vctrs::vec_cast
vec_cast.fs_bytes.double <- function(x, to, ...) {
as_fs_bytes(x)
}
#' @exportS3Method vctrs::vec_cast
vec_cast.double.fs_bytes <- function(x, to, ...) {
unclass(x)
}

#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.fs_bytes.integer <- function(x, y, ...) {
x
}
#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.integer.fs_bytes <- function(x, y, ...) {
y
}

#' @exportS3Method vctrs::vec_cast
vec_cast.fs_bytes.integer <- function(x, to, ...) {
as_fs_bytes(x)
}
#' @exportS3Method vctrs::vec_cast
vec_cast.integer.fs_bytes <- function(x, to, ...) {
unclass(x)
}
10 changes: 8 additions & 2 deletions R/fs_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ print.fs_path <- function(x, ..., max = getOption("max.print")) {
new_fs_path(paste0(e1, e2))
}

#' @exportS3Method pillar::pillar_shaft
pillar_shaft.fs_path <- function(x, ..., min_width = 10, shorten = getOption("fs.fs_path.shorten", "front")) {
pillar::new_pillar_shaft_simple(colourise_fs_path(x), ..., min_width = min_width, shorten = shorten)
}

#' @exportS3Method pillar::type_sum
type_sum.fs_path <- function(x) {
"fs::path"
}
Expand Down Expand Up @@ -159,25 +161,29 @@ xtfrm.fs_path <- function(x, ...) {
NextMethod("xterm")
}

# All functions below registered in .onLoad

#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.fs_path.fs_path <- function(x, y, ...) {
x
}
#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.fs_path.character <- function(x, y, ...) {
x
}
#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.character.fs_path <- function(x, y, ...) {
y
}

# Note order of class is the opposite as for ptype2
#' @exportS3Method vctrs::vec_cast
vec_cast.fs_path.fs_path <- function(x, to, ...) {
x
}
#' @exportS3Method vctrs::vec_cast
vec_cast.fs_path.character <- function(x, to, ...) {
as_fs_path(x)
}
#' @exportS3Method vctrs::vec_cast
vec_cast.character.fs_path <- function(x, to, ...) {
unclass(x)
}
18 changes: 16 additions & 2 deletions R/fs_perms.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,61 +195,75 @@ setOldClass(c("fs_perms", "integer"), integer())
unclass(a & b) == unclass(b)
}

#' @exportS3Method pillar::pillar_shaft
pillar_shaft.fs_perms <- function(x, ...) {
pillar::new_pillar_shaft_simple(format.fs_perms(x), ...)
}

#' @exportS3Method pillar::type_sum
type_sum.fs_perms <- function(x) {
"fs::perms"
}

# All functions below registered in .onLoad

#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.fs_perms.fs_perms <- function(x, y, ...) {
x
}
#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.fs_perms.double <- function(x, y, ...) {
x
}
#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.double.fs_perms <- function(x, y, ...) {
y
}

# Note order of class is the opposite as for ptype2
#' @exportS3Method vctrs::vec_cast
vec_cast.fs_perms.fs_perms <- function(x, to, ...) {
x
}
#' @exportS3Method vctrs::vec_cast
vec_cast.fs_perms.double <- function(x, to, ...) {
as_fs_perms(x)
}
#' @exportS3Method vctrs::vec_cast
vec_cast.double.fs_perms <- function(x, to, ...) {
unclass(x)
}

#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.fs_perms.integer <- function(x, y, ...) {
x
}
#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.integer.fs_perms <- function(x, y, ...) {
y
}

#' @exportS3Method vctrs::vec_cast
vec_cast.fs_perms.integer <- function(x, to, ...) {
as_fs_perms(x)
}
#' @exportS3Method vctrs::vec_cast
vec_cast.integer.fs_perms <- function(x, to, ...) {
unclass(x)
}

#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.fs_perms.character <- function(x, y, ...) {
x
}
#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.character.fs_perms <- function(x, y, ...) {
y
}

#' @exportS3Method vctrs::vec_cast
vec_cast.fs_perms.character <- function(x, to, ...) {
as_fs_perms(x)
}
#' @exportS3Method vctrs::vec_cast
vec_cast.character.fs_perms <- function(x, to, ...) {
as.character(x)
}
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ is_windows <- function() {

# This is needed to avoid checking the class of fs_path objects in the
# tests.
# @export
#' @exportS3Method testthat::compare
compare.fs_path <- function(x, y, ...) {
if (identical(class(y), "character")) {
class(x) <- NULL
Expand All @@ -42,7 +42,7 @@ compare.fs_path <- function(x, y, ...) {
NextMethod("compare")
}

# @export
#' @exportS3Method testthat::compare
compare.fs_perms <- function(x, y, ...) {
if (!inherits(y, "fs_perms")) {
y <- as.character(as_fs_perms(y))
Expand Down
70 changes: 0 additions & 70 deletions R/zzz.R

This file was deleted.

0 comments on commit 49f96b9

Please sign in to comment.