Written and maintained by CASRAI Editorial Board
Last updated
To convert text to upper case in R, call toupper(x). It is part of base R, needs no package, and returns a character vector the same length as x. For locale-aware casing, the stringr function str_to_upper(string, locale = "en") does the same job and lets you name the locale. This page covers the exact behaviour of both, including locale-sensitive cases such as the Turkish letter i.
What it is used for in research
Upper-casing is a data-cleaning step. Identifiers, sample labels, country codes and gene or instrument symbols often arrive in mixed case across files, and a join or match on text is case-sensitive in R. Converting both sides to one case first makes values such as “ab12” and “AB12” compare as equal. It also standardises labels for tables and figure legends. Put the conversion in a script rather than editing cells by hand so the step is recorded; see data wrangling for where text cleaning fits in a workflow.
Install or access (official source only)
toupper(), tolower(), casefold() and chartr() are documented together on one page of the R base manual and ship with R, so there is nothing to install. R itself is distributed through CRAN, the Comprehensive R Archive Network.
The stringr functions come from the stringr package in the tidyverse. Install it once and load it in each session:
install.packages("stringr")
library(stringr)
Step-by-step: convert text to upper case
- Convert a string with
toupper(). The R manual’s own example usesx <- "MiXeD cAsE 123";toupper(x)returns"MIXED CASE 123". Digits and other non-alphabetic characters are left unchanged. - Convert a whole vector or data frame column.
toupper()accepts a character vector, or an object that can be coerced to character withas.character, and returns a character vector of the same length. To overwrite a column:df$id <- toupper(df$id). - Use
casefold()if you prefer one function for both directions.casefold(x, upper = TRUE)translates to upper case; with the defaultupper = FALSEit translates to lower case.casefoldis a wrapper, socasefold(x, upper = TRUE)behaves liketoupper(x). - Use stringr when you need a locale. With the package loaded,
dog <- "The quick brown dog"andstr_to_upper(dog)give"THE QUICK BROWN DOG". The same package offersstr_to_lower(),str_to_title()("The Quick Brown Dog") andstr_to_sentence(), which turns"the quick brown dog"into"The quick brown dog". - Capitalise only the first letter. Base R has no single function for this; the R manual’s examples build “Mixed Case” output by applying
toupper()to the first character taken withsubstring(). In stringr,str_to_sentence()andstr_to_title()cover the common cases.
Output and how to read it
The result is a character vector with the same length and attributes as the input after coercion. Only letters change; digits, spaces and punctuation come back as they went in. If you pass a factor, the coercion to character means you get a character vector back, not a factor, so convert it back with factor() if later code expects levels.
Troubleshooting
Accented or non-English letters do not change
The R manual states that these functions are platform-dependent and usually rely on operating-system services, which can be limited, for example covering only ASCII characters in 8-bit locales. What counts as an alphabetic character also depends on the platform. If accented letters stay lower case, check your session’s locale and encoding first.
The result is not what a language expects (Turkish i)
Casing rules differ by language. The stringr reference shows str_to_upper("i") returning "I", while str_to_upper("i", "tr") returns "İ", the dotted capital used in Turkish. The default locale is "en", set so that behaviour is consistent across platforms; other values come from stringi::stri_locale_list().
Character count changes
The R manual notes that more than one character can map to a single upper-case character, so do not assume a mapping is always one-to-one when you compare string lengths before and after.
You passed something that is not text
Numbers, factors and other objects are coerced with as.character first. Check class(x) if a result looks surprising.
Free alternatives
| Function | Package | Locale argument | Notes |
|---|---|---|---|
toupper(x) |
base R | No | Platform-dependent; uses OS services |
casefold(x, upper = TRUE) |
base R | No | Wrapper that behaves like toupper(x) |
str_to_upper(string, locale = "en") |
stringr | Yes | Default "en" keeps behaviour consistent across platforms |
str_to_title(), str_to_sentence() |
stringr | Yes | Title case and sentence case instead of all capitals |
All of the above are free and open source. For working with the rest of a cleaned data set, see histograms in R and maps in R for plotting once labels are standardised.
FAQ
How do I make a string upper case in R?
Use toupper("text"), which returns "TEXT". It works on a single string or an entire character vector.
What is the difference between toupper() and casefold()?
casefold(x, upper = TRUE) is a wrapper and behaves like toupper(x). The advantage is a single function with an upper switch.
How do I capitalise only the first letter in R?
Base R has no single function for it; the R manual’s examples apply toupper() to the first character of each word taken with substring(). In stringr, str_to_sentence() and str_to_title() cover the common cases.
Why does str_to_upper("i") return a different letter in Turkish?
Because casing rules depend on language. str_to_upper("i") returns "I", while str_to_upper("i", "tr") returns "İ".
Does upper-casing in R depend on my computer?
Yes for base R: the manual describes the functions as platform-dependent. stringr’s str_to_upper() takes a locale argument with default "en" for consistent results.
Sources (official docs)
- R base manual, chartr, tolower, toupper, casefold (checked 2026-10-29).
- stringr reference, Convert string to upper case, lower case, title case, or sentence case (checked 2026-10-29).








