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.
Animation should look like:
As always, code is available in at the Github in same Useless_R_function repository.
Happy R-coding!
[…] by data_admin [This article was first published on R – TomazTsql, and kindly contributed to R-bloggers]. (You can report issue about the content on this page […]
LikeLiked by 1 person
[…] Tomaz Kastrun is already counting down to next year: […]
LikeLiked by 1 person
This is nice! I’d recommend using “\u2591” and “\u2593” instead so you don’t get any weird non-ASCI warnings 😉
LikeLiked by 1 person
[…] article was first published on R – TomazTsql, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here) […]
LikeLiked by 1 person