Data Science Desktop Survival Guide
by Graham Williams |
|||||
Glue Strings Together |
dsname <- "weatherAUS"
nobs <- nrow(weatherAUS) starts <- min(weatherAUS$Date) glue("The {dsname} dataset", " has just less than {comma(nobs + 1)} observations,", " starting from {format(starts, '%-d %B %Y')}.")
We can manually wrap the sentence. |
glue("
The {dsname} dataset has just less than {comma(nobs + 1)} observations starting from {format(starts, '%-d %B %Y')}. ")
Notice how the initial and last empty lines are handled “as expected”, and the line split is maintained. Named arguments within the function call can be used to assign values to variables that only exist in the scope of the function call. |
glue("
The {dsname} dataset has just less than {comma(nobs + 1)} observations starting from {format(starts, '%-d %B %Y')}. ", dsname = "weather", nobs = nrow(weather), starts = min(weather$Date))
We can also see the effect of indenting lines in this example, where the indentation is retained. |