From e180285c4e0f4a7c27f965d2f080f82d5657687b Mon Sep 17 00:00:00 2001 From: Mauricio 'Pacha' Vargas Sepulveda Date: Sat, 3 Aug 2024 13:05:57 -0400 Subject: [PATCH] indentation --- R/tessdata.R | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/R/tessdata.R b/R/tessdata.R index 5ca10af..62577ef 100644 --- a/R/tessdata.R +++ b/R/tessdata.R @@ -26,9 +26,8 @@ #' @param progress print progress while downloading #' @references [tesseract wiki: training data](https://tesseract-ocr.github.io/tessdoc/Data-Files) #' @examples \dontrun{ -#' if (is.na(match("fra", tesseract_info()$available))) { +#' if(is.na(match("fra", tesseract_info()$available))) #' tesseract_download("fra") -#' } #' french <- tesseract("fra") #' text <- ocr("https://jeroen.github.io/images/french_text.png", engine = french) #' cat(text) @@ -36,7 +35,7 @@ tesseract_download <- function(lang, datapath = NULL, best = FALSE, progress = interactive()) { stopifnot(is.character(lang)) - if (!length(datapath)) { + if(!length(datapath)){ warn_on_linux() datapath <- tesseract_info()$datapath } @@ -65,13 +64,11 @@ tesseract_download <- function(lang, datapath = NULL, best = FALSE, progress = i noprogress = !isTRUE(progress) )) - if (progress) { + if(progress) cat("\n") - } - if (req$status_code != 200) { + if(req$status_code != 200) stop("Download failed: HTTP ", req$status_code, call. = FALSE) - } writeBin(req$content, destfile) @@ -81,19 +78,18 @@ tesseract_download <- function(lang, datapath = NULL, best = FALSE, progress = i progress_fun <- function(down, up) { total <- down[[1]] now <- down[[2]] - pct <- if (length(total) && total > 0) { - paste0("(", round(now / total * 100), "%)") + pct <- if(length(total) && total > 0){ + paste0("(", round(now/total * 100), "%)") } else { "" } - if (now > 10000) { + if(now > 10000) cat("\r Downloaded:", sprintf("%.2f", now / 2^20), "MB ", pct) - } TRUE } warn_on_linux <- function() { - if (identical(.Platform$OS.type, "unix") && !identical(Sys.info()[["sysname"]], "Darwin")) { + if(identical(.Platform$OS.type, "unix") && !identical(Sys.info()[["sysname"]], "Darwin")){ warning("On Linux you should install training data via yum/apt. Please check the manual page.", call. = FALSE) } }