## Microscopic

From our perspective to the largest scale measured, and then to the smallest scale measurable. This video illustrates the effect of adding or subtracting another zero on a given scale. The largest distance measurable in the observable universe was calculated to be about 47 billion lightyears; about $4.4 \times 10^{10} \mbox{ m}$. The smallest scale measurable, or at least defined to my knowledge, is the Planck length; $\ell_\text{P} \approx 1.6 \times 10^{-35} \mbox{ m}$. One nucleotide (the molecules that are the building blocks of DNA) measures about 0.33 nm. Stretched out, human chromosome 1, with its approximately 249 million nucleotides, would be about 8 cm long. The whole human genome would be about 3 m in length. Not much compared to galactic distances, but still quite interesting.

## A simple progress-bar in R

A progress-bar is quite useful for displaying the current state of an iterating process, such as in a loop called using the for function in R.

Below you can see my very quick and easy to use function for employing the progress-bar feature in R. Here is the code:

#
# An easy progress bar all-in-one function
#

ProgressBar <- function(x = NA) {
StartProgress <- function(x) {
width <- getOption("width")
width <- if (100 > (width - 10)) width - 10 else 100
.progressbar <<- txtProgressBar(min=0, max=x, style=3, width=width)
.progressmax <<- x
.progressint <<- 0
}
CloseProgress <- function() {
if (exists(".progressbar", envir=.GlobalEnv)) {
close(.progressbar)
rm(list=c(".progressbar", ".progressmax", ".progressint"),
envir=.GlobalEnv)
}
}
if (is.null(x)) {
CloseProgress()
} else {
if (!is.na(x)) {
CloseProgress()
StartProgress(x)
} else {
if (exists(".progressbar", envir=.GlobalEnv)) {
.progressint <<- .progressint + 1
if (.progressint <= .progressmax)
setTxtProgressBar(.progressbar, .progressint)
if (.progressint == .progressmax)
CloseProgress()
}
}
}
}

To use the code, one simply has to tell the function how many iterations of a loop are coming; this is the only parameter. The total number of iterations, of course, has to be known. Otherwise the function does not know when 100% is reached. Then, the function has to be called within a loop, but without any parameter. After the loop, the progress-bar function is called again, with “NULL” as parameter value, to end the display of the progress-bar; but this is optional.

Below is an example of how to use the ProgressBar function:

# define how many iterations will be performed in the loop
x <- 666

# start by giving the total number of iterations
ProgressBar(x)

# call function within a loop
for (i in 1:x) {
Sys.sleep(0.025)
ProgressBar()
}

# end the progress bar (optional)
ProgressBar(NULL)

The resulting output is displayed in the R console, and looks like this (when completed):

|===============================================================| 100%

I used this function in many applications, or just to see how long some runs are going to take while testing a new code. I hope you enjoy it.