R/utils.R

Defines functions desenhar classificar is_windows

#' @export
desenhar <- function(d) {
  p <- ggplot2::ggplot(d, ggplot2::aes(x = x, y = y))
  p <- p + 
    ggplot2::coord_equal() + 
    ggplot2::theme_bw()
  if(!is.null(d$grupo)) {
    p <- p + ggplot2::geom_point(shape = 15)
    p <- p + ggplot2::facet_wrap(~grupo, scales = 'free_y', ncol = 5)
  } else {
    p <- p + ggplot2::geom_point(colour = d$cor, shape = 15, size = 3)
  }
  p +
    ggplot2::scale_x_continuous(breaks = 0:1000 * 5) +
    ggplot2::scale_y_continuous(breaks = 0:100 * 5)
}

#' @export
classificar <- function(d, letras = NULL, path) {
  if(is.null(letras)) {
    letras <- readline(prompt="Letras: ")
  }
  r <- strsplit(letras, '')[[1]]
  for(i in 1:5) {
    aux <- d[d$grupo == i, ]
    nm <- sprintf('%s/%s_%07d.rds', path, r[i],
                  as.integer(round(stats::runif(1, 1, 1e8-1))))
    saveRDS(aux, nm)
  }
}

#' Pipe operator
#'
#' See \code{\link[magrittr]{\%>\%}} for more details.
#'
#' @name %>%
#' @rdname pipe
#' @keywords internal
#' @export
#' @importFrom magrittr %>%
#' @usage lhs \%>\% rhs
NULL

is_windows <- function() {
  stringr::str_detect( tolower(utils::sessionInfo()$running), "windows")
}
jtrecenti/captchasaj documentation built on May 20, 2019, 3:16 a.m.