"tga"[1] "tga"
The function stringr::str_view() allows you to view/print the “raw contents” of a string.
Normal R method to view a string.
Tidyverse method to view string with stringr::str_view().
The differences of str_view() to the normal method are:
| between the index ([1]) and the string (tga).Create a character vector.
Print vector through normal R method.
View vector with str_view().
Notice that each vector element is printed on a new line with str_view().
There are may special characters that can be used in strings. str_view() is especially useful in how it presents these.
The three main white spaces in R are:
" ": A space."\t": A tab."\n": A new line.Create a vector demonstrating these three.
Print this vector with the normal R method.
View with str_view().
In this case notice:
\t) is within curly braces ({}), represented as {\t}.To include double quotes within strings denoted by double quotes we need to “escape” the double quotes. We can carry this out with \.
Create a string containing a double quote. Note, we can include single quotes (') normally as we are not using them to denote the string.
Printing the string normally with R shows the escape character (\)
Viewing the string with str_view() does not show the escape character. Instead it aims to display the text how a human would read it, rather than a computer. This is very useful to ensure any escape characters in the string work as intended.
To add to the complexity you can escape escape characters with an escape character.
Unicode can be used to include other various special symbols. Examples include:
\u00b5\u20ac\U0001f60eNormal R will print out symbol.
str_view() will also print out the symbol.
For more unicode characters please see: Wikipedia page of List of Unicode characters. For these you need to change U+ to u and you can use lower case letters instead of upper case.
Missing values are represented as NA in R.
When you run the above code you will notice that the NA is coloured with a different colour than the string "NA".