s3.R

library(tidyverse)

x <- 1:3
y <- c(1, 3, 8)

lmout <- lm(y~x)
class(lmout)

lmout
print
print.lm


getAnywhere(print.lm)


stats:::print.lm
mtcars_new <- mtcars %>% as_tibble()

dog_count <- function(df, ...){
  out <- df %>% count(..., sort = TRUE)
  if (ncol(out) == 2){
  class(out) <- c("one_col", "tbl_df", "tbl", "data.frame")
  }

  else {

  }


}


class(df) <- c("one_col", "tbl_df", "tbl", "data.frame")

plot.one_col <- function(df){

names <- names(df)

    df %>%
    ggplot() +
    geom_bar(aes(x = .data[[names[1]]], y = .data[[names[2]]]), stat = "identity") +
    labs(x = names[1],
         y = names[2])
}

plot(1:10)
plot(df) +
  labs(title = "hej")


b <- methods(plot)

"plot.one_col" %in% b

getAnywhere(plot.one_col)
davidbaniadam/rispacs documentation built on Nov. 4, 2019, 9:43 a.m.