Progress bar showing the number of days until end of the year. Yes, only based on the days and not hour. And needless to say, the progress is soothing using ASCII charts.

So the function is fair to say, simple and useless.

 yearProgress <- function(){           year <- format(Sys.Date(), format="%Y")           difference <- as.integer(Sys.Date()-as.Date(paste0(year, "-01-01")))/365            WidthBar <- 50           LenProgress <- 40           cursor <- c("\\","|","/","-")                      for (LenStep in 1:LenProgress) {             step <- round((LenStep/LenProgress * (WidthBar-5))*difference)             charSpinningCursor <- (LenStep %% 4)+1                          text <- sprintf('%s |%s%s % 3s%%',                              cursor[charSpinningCursor],                             strrep('▓', step),                             strrep('░', WidthBar-step-5), round(LenStep/LenProgress*difference*100.00, digits=2)                                                          )                          cat("Yearly progress so far ",year, "...\n")             cat(text)               Sys.sleep(0.2)             cat(if (LenStep == LenProgress)                  '\n' else '\014'                 )            } } 

And run the function:

 # Run function yearProgress() 

And the result should look like as a progress bar with the graphics with spinning cursor in front of the bar.

Progress bar

Animation should look like:

Animated progress bar

As always, code is available in at the Github in same Useless_R_function repository.

Happy R-coding!


This post is ad-supported