[This article was first published on R – TomazTsql, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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!
To leave a comment for the author, please follow the link and comment on their blog: R – TomazTsql.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.