EVOLUTION-MANAGER
Edit File: make_clean_names.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Cleans a vector of text, typically containing the names of an...</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for make_clean_names {janitor}"><tr><td>make_clean_names {janitor}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Cleans a vector of text, typically containing the names of an object.</h2> <h3>Description</h3> <p>Resulting strings are unique and consist only of the <code>_</code> character, numbers, and letters. By default, the resulting strings will only consist of ASCII characters, but non-ASCII (e.g. Unicode) may be allowed by setting <code>ascii=FALSE</code>. Capitalization preferences can be specified using the <code>case</code> parameter. </p> <p>For use on the names of a data.frame, e.g., in a <code>`%>%`</code> pipeline, call the convenience function <code><a href="clean_names.html">clean_names</a></code>. </p> <p>When <code>ascii=TRUE</code> (the default), accented characters are transliterated to ASCII. For example, an "o" with a German umlaut over it becomes "o", and the Spanish character "enye" becomes "n". </p> <p>The order of operations is: make replacements, (optional) ASCII conversion, remove initial spaces and punctuation, apply <code>base::make.names()</code>, apply <code>snakecase::to_any_case</code>, and add numeric suffixes to resolve any duplicated names. </p> <p>This function relies on <code>snakecase::to_any_case</code> and can take advantage of its versatility. For instance, an abbreviation like "ID" can have its capitalization preserved by passing the argument <code>abbreviations = "ID"</code>. See the documentation for <code><a href="../../snakecase/html/to_any_case.html">snakecase::to_any_case</a></code> for more about how to use its features. </p> <p>On some systems, not all transliterators to ASCII are available. If this is the case on your system, all available transliterators will be used, and a warning will be issued once per session indicating that results may be different when run on a different system. That warning can be disabled with <code>options(janitor_warn_transliterators=FALSE)</code>. </p> <p>If the objective of your call to <code>make_clean_names()</code> is only to translate to ASCII, try the following instead: <code>stringi::stri_trans_general(x, id="Any-Latin;Greek-Latin;Latin-ASCII")</code>. </p> <h3>Usage</h3> <pre> make_clean_names( string, case = "snake", replace = c(`'` = "", `"` = "", `%` = "_percent_", `#` = "_number_"), ascii = TRUE, use_make_names = TRUE, sep_in = "\\.", transliterations = "Latin-ASCII", parsing_option = 1, numerals = "asis", ... ) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>string</code></td> <td> <p>A character vector of names to clean.</p> </td></tr> <tr valign="top"><td><code>case</code></td> <td> <p>The desired target case (default is <code>"snake"</code>) will be passed to <code>snakecase::to_any_case()</code> with the exception of "old_janitor", which exists only to support legacy code (it preserves the behavior of <code>clean_names()</code> prior to addition of the "case" argument (janitor versions <= 0.3.1). "old_janitor" is not intended for new code. See <code><a href="../../snakecase/html/to_any_case.html">to_any_case</a></code> for a wide variety of supported cases, including "sentence" and "title" case.</p> </td></tr> <tr valign="top"><td><code>replace</code></td> <td> <p>A named character vector where the name is replaced by the value.</p> </td></tr> <tr valign="top"><td><code>ascii</code></td> <td> <p>Convert the names to ASCII (<code>TRUE</code>, default) or not (<code>FALSE</code>).</p> </td></tr> <tr valign="top"><td><code>use_make_names</code></td> <td> <p>Should <code>make.names()</code> be applied to ensure that the output is usable as a name without quoting? (Avoiding <code>make.names()</code> ensures that the output is locale-independent but quoting may be required.)</p> </td></tr> <tr valign="top"><td><code>sep_in</code></td> <td> <p>(short for separator input) if character, is interpreted as a regular expression (wrapped internally into <code>stringr::regex()</code>). The default value is a regular expression that matches any sequence of non-alphanumeric values. All matches will be replaced by underscores (additionally to <code>"_"</code> and <code>" "</code>, for which this is always true, even if <code>NULL</code> is supplied). These underscores are used internally to split the strings into substrings and specify the word boundaries.</p> </td></tr> <tr valign="top"><td><code>transliterations</code></td> <td> <p>A character vector (if not <code>NULL</code>). The entries of this argument need to be elements of <code>stringi::stri_trans_list()</code> (like "Latin-ASCII", which is often useful) or names of lookup tables (currently only "german" is supported). In the order of the entries the letters of the input string will be transliterated via <code>stringi::stri_trans_general()</code> or replaced via the matches of the lookup table. When named character elements are supplied as part of 'transliterations', anything that matches the names is replaced by the corresponding value. You should use this feature with care in case of <code>case = "parsed"</code>, <code>case = "internal_parsing"</code> and <code>case = "none"</code>, since for upper case letters, which have transliterations/replacements of length 2, the second letter will be transliterated to lowercase, for example Oe, Ae, Ss, which might not always be what is intended. In this case you can make usage of the option to supply named elements and specify the transliterations yourself.</p> </td></tr> <tr valign="top"><td><code>parsing_option</code></td> <td> <p>An integer that will determine the parsing_option. </p> <ul> <li><p>1: <code>"RRRStudio" -> "RRR_Studio"</code> </p> </li> <li><p>2: <code>"RRRStudio" -> "RRRS_tudio"</code> </p> </li> <li><p>3: <code>"RRRStudio" -> "RRRSStudio"</code>. This will become for example <code>"Rrrstudio"</code> when we convert to lower camel case. </p> </li> <li><p>-1, -2, -3: These <code>parsing_options</code>'s will suppress the conversion after non-alphanumeric values. </p> </li> <li><p>0: no parsing </p> </li></ul> </td></tr> <tr valign="top"><td><code>numerals</code></td> <td> <p>A character specifying the alignment of numerals (<code>"middle"</code>, <code>left</code>, <code>right</code>, <code>asis</code> or <code>tight</code>). I.e. <code>numerals = "left"</code> ensures that no output separator is in front of a digit.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Arguments passed on to <code><a href="../../snakecase/html/to_any_case.html">snakecase::to_any_case</a></code> </p> <dl> <dt><code>abbreviations</code></dt><dd><p>character. (Case insensitive) matched abbreviations are surrounded by underscores. In this way, they can get recognized by the parser. This is useful when e.g. <code>parsing_option</code> 1 is needed for the use case, but some abbreviations but some substrings would require <code>parsing_option</code> 2. Furthermore, this argument also specifies the formatting of abbreviations in the output for the cases title, mixed, lower and upper camel. E.g. for upper camel the first letter is always in upper case, but when the abbreviation is supplied in upper case, this will also be visible in the output. </p> <p>Use this feature with care: One letter abbreviations and abbreviations next to each other are hard to read and also not easy to parse for further processing.</p> </dd> <dt><code>sep_out</code></dt><dd><p>(short for separator output) String that will be used as separator. The defaults are <code>"_"</code> and <code>""</code>, regarding the specified <code>case</code>. When <code>length(sep_out) > 1</code>, the last element of <code>sep_out</code> gets recycled and separators are incorporated per string according to their order.</p> </dd> <dt><code>unique_sep</code></dt><dd><p>A string. If not <code>NULL</code>, then duplicated names will get a suffix integer in the order of their appearance. The suffix is separated by the supplied string to this argument.</p> </dd> <dt><code>empty_fill</code></dt><dd><p>A string. If it is supplied, then each entry that matches "" will be replaced by the supplied string to this argument.</p> </dd> <dt><code>prefix</code></dt><dd><p>prefix (string).</p> </dd> <dt><code>postfix</code></dt><dd><p>postfix (string).</p> </dd> </dl> </td></tr> </table> <h3>Value</h3> <p>Returns the "cleaned" character vector. </p> <h3>See Also</h3> <p><code><a href="../../snakecase/html/to_any_case.html">to_any_case</a>()</code> </p> <h3>Examples</h3> <pre> # cleaning the names of a vector: x <- structure(1:3, names = c("name with space", "TwoWords", "total $ (2009)")) x names(x) <- make_clean_names(names(x)) x # now has cleaned names # if you prefer camelCase variable names: make_clean_names(names(x), "small_camel") # similar to janitor::clean_names(poorly_named_df): # not run: # make_clean_names(names(poorly_named_df)) </pre> <hr /><div style="text-align: center;">[Package <em>janitor</em> version 2.1.0 <a href="00Index.html">Index</a>]</div> </body></html>