R paste0
Append one string to another to assemble a printable identifier.
A simple example
paste0
- Start with "a" and "b"
- Do this Join end to end
- Result "ab"
value <- "a"
other <- "b"
cat(paste0(value, other), "\n", sep = "")
ab
Syntax
paste0(value, other)
Run these examples in R
Save one example at a time as Lesson.R. Use R 4.x.
Rscript --vanilla Lesson.RAttach a seat number to a row
A label printer receives an identifier in separate pieces instead of one finished string. Assemble the pieces in the intended order and check the separator where the two fields meet.
value <- "Row B-"
other <- "12"
cat(paste0(value, other), "\n", sep = "")
Row B-12
The prefix already contains the hyphen.
Add an extension to a receipt
An export routine receives the base name for a receipt. Add the extension to produce the printable filename and keep the original name available for any other export format.
value <- "march"
other <- ".pdf"
cat(paste0(value, other), "\n", sep = "")
march.pdf
The extension includes its own leading dot.
Build a parcel shelf identifier
The shelf prefix already includes the hyphen. Combine the two fragments in order without adding another separator. What label goes to the printer?
What to watch for
Insert any required separator explicitly. Keep the returned text in languages with immutable strings.