R/trailingDigits.R

Defines functions trailingDigits

Documented in trailingDigits

#' Adds zeros to the end of hs column to make both columns of equal length
#'
#' @export
#'

trailingDigits <- function(from, to, digit) {

  from_len <- stringr::str_length(from)
  to_len   <- stringr::str_length(to)

  to <- ifelse(from_len > to_len,
               paste0(to,
                      vapply(from_len - to_len,
                             FUN = function(x) {
                               paste0(rep.int(digit, times = x), collapse = "")
                             },
                             FUN.VALUE = character(1)
                      )
               ),
               to

  )
  to

}
SWS-Methodology/faoswsTrade documentation built on Feb. 13, 2023, 1:04 a.m.