

{"id":4980,"date":"2017-02-06T00:11:31","date_gmt":"2017-02-06T05:11:31","guid":{"rendered":"https:\/\/rud.is\/b\/?p=4980"},"modified":"2018-03-07T17:24:18","modified_gmt":"2018-03-07T22:24:18","slug":"strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr","status":"publish","type":"post","link":"https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/","title":{"rendered":"Strung Out On String Ops &#8211; A Brief Comparison of stringi and stringr"},"content":{"rendered":"<p>I made a promise to someone that my next blog would be about <code>stringi<\/code> vs <code>stringr<\/code> and I intend to keep said promise.<\/p>\n<p><code>stringr<\/code> and <code>stringi<\/code> do &#8220;string operations&#8221;: find, replace,  match, extract, convert, transform, etc.<\/p>\n<p>The <code>stringr<\/code> package is now part of the <code>tidyverse<\/code> and is 100% focused on string processing and is pretty much a wrapper package for <code>stringi<\/code>. The <code>stringi<\/code> package wraps chunks of the <a href=\"http:\/\/icu-project.org\/apiref\/icu4c\/\"><code>icu4c<\/code><\/a> library but the <code>stringi<\/code> API frmaing was actually based on the patterns in the <code>stringr<\/code> package API. <code>stringr<\/code> did not wrap <code>stringi<\/code> at the time but does now and <code>stringi<\/code> strays a bit (on occasion) from string processing since the entire <code>icu4c<\/code> library is at it&#8217;s disposal. Confused? Good! There&#8217;s more!<\/p>\n<p>The impetus for asking me to blog about this is that I&#8217;m known to say &#8220;<em>just use <code>stringi<\/code><\/em>&#8221; in situations where someone has taken a <code>stringr<\/code> &#8220;shortcut&#8221;. Let me explain why.<\/p>\n<h3>Readers Digest<\/h3>\n<p>First, you need to read pages 4-5 of <a href=\"https:\/\/cran.r-project.org\/web\/packages\/stringi\/stringi.pdf\">the <code>stringi<\/code> manual<\/a> [PDF] and then the <a href=\"https:\/\/cran.r-project.org\/web\/packages\/stringr\/vignettes\/stringr.html\"><code>stringr<\/code> vignette<\/a>. I&#8217;m not duplicating the information on those pages. The TL;DR on them is:<\/p>\n<ul>\n<li>that <code>stringr<\/code> makes some (valid) assumptions about defaults for the <code>stringi<\/code> calls it wraps<\/li>\n<li><code>stringr<\/code> is much easier to initially grok as it&#8217;s very focused and has far fewer functions<\/li>\n<li>they both use <a href=\"http:\/\/userguide.icu-project.org\/strings\/regexp\">ICU regular expressions<\/a><\/li>\n<li><code>stringi<\/code> includes more than string processing and has far more total functions:<\/li>\n<\/ul>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/02\/ct-1.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"4982\" data-permalink=\"https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/ct-1\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/02\/ct-1.png?fit=1536%2C480&amp;ssl=1\" data-orig-size=\"1536,480\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"ct-1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/02\/ct-1.png?fit=510%2C159&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/02\/ct-1.png?resize=510%2C159&#038;ssl=1\" alt=\"\" width=\"510\" height=\"159\" class=\"aligncenter size-full wp-image-4982\" \/><\/a><\/p>\n<p>As noted, <code>stringr<\/code> wraps <code>stringi<\/code> calls (for the most part) and some of the <code>stringr<\/code> functions reference more than one <code>stringi<\/code> function:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/02\/fun-1.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"4983\" data-permalink=\"https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/fun-1\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/02\/fun-1.png?fit=1536%2C672&amp;ssl=1\" data-orig-size=\"1536,672\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"fun-1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/02\/fun-1.png?fit=510%2C223&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/02\/fun-1.png?resize=510%2C223&#038;ssl=1\" alt=\"\" width=\"510\" height=\"223\" class=\"aligncenter size-full wp-image-4983\" \/><\/a><\/p>\n<p>That&#8217;s my primary defense for &#8220;<em>just use <code>stringi<\/code><\/em>&#8221; \u2014 <code>stringr<\/code> &#8220;just uses&#8221; it and you are forced to install <code>stringi<\/code> on every system <code>stringr<\/code> is on, so why introduce another dependency into your code?<\/p>\n<h3>All Wrapped Up<\/h3>\n<p>These are the <code>stringr<\/code> functions with a 1:~1 correspondence to <code>stringi<\/code> functions:<\/p>\n<pre><code>stri_c stri_conv stri_count stri_detect stri_dup stri_extract stri_extract_all stri_join stri_length stri_locate stri_locate_all stri_match stri_match_all stri_order stri_pad stri_replace stri_replace_all stri_replace_na stri_sort stri_split stri_split_fixed stri_sub stri_sub&lt;- stri_subset stri_trim stri_wrap\n<\/code><\/pre>\n<p>I used 1:~1 since at the heart of the string processing capabilities of both packages lies the concept of granular control of matching behaviour. Specifically, there are four modes (so it&#8217;s really 1:4?):<\/p>\n<ul>\n<li><strong>fixed<\/strong>: Compare literal bytes in the string. This is very fast, but not usually what you want for non-ASCII character sets<\/li>\n<li><strong>coll<\/strong>: Compare strings respecting standard collation rules<\/li>\n<li><strong>regex<\/strong>: The default. Uses ICU regular expressions<\/li>\n<li><strong>boundary<\/strong>: Match boundaries between things<\/li>\n<\/ul>\n<p><code>stringr<\/code> has function modifiers around <code>pattern<\/code> to handle those whereas <code>stringi<\/code> requires explicit function calls. So, you&#8217;d do the following to replace a fixed char\/byte sequence in each package:<\/p>\n<ul>\n<li><code>stri_replace_all_fixed(\"Lorem i.sum dolor sit amet, conse.tetur adipisicing elit.\", \".\", \"#\")<\/code><\/li>\n<li><code>str_replace_all(\"Lorem i.sum dolor sit amet, conse.tetur adipisicing elit.\", fixed(\".\"), \"#\")<\/code><\/li>\n<\/ul>\n<p>In that case there&#8217;s not much in the way of keystroke savings, but the default mode of <code>stringr<\/code> is to use regex replacement and you do save both an <code>i<\/code> and <code>_regex<\/code> for that but add one more function call in-between you and your goal. When you work with multi-gigabyte character structures (as I do), those milliseconds often add up. If keystrokes > milliseconds in your workflow, you may want to stick with <code>stringr<\/code>.<\/p>\n<h3>Treasure Hunting in stringi<\/h3>\n<p>If you take some time to look at what&#8217;s in <code>stringi<\/code> you&#8217;ll find quite a bit (I excluded the fixed\/coll\/reged\/boundary versions for brevity):<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rud.is\/dl\/stringi.svg\" alt=\"\" \/><\/p>\n<p>That&#8217;s an SVG, so zoom in as much as you need to to read it.<\/p>\n<p>These are <code>stringi<\/code> <em>gems<\/em>:<\/p>\n<ul>\n<li><code>stri_stats_general<\/code> (stats abt a character vector)<\/li>\n<li><code>stri_trans_totitle<\/code> (For When You Want Title Case)<\/li>\n<li><code>stri_flatten<\/code> (<code>paste0<\/code> but better defaults)<\/li>\n<li><code>stri_rand_strings<\/code> (random strings)<\/li>\n<li><code>stri_rand_lipsum<\/code> (random Lorem Ipsum lines!)<\/li>\n<li><code>stri_count_words<\/code>, <code>stri_extract_all_words<\/code>, <code>stri_extract_first_words<\/code>, <code>stri_extract_last_words<\/code><\/li>\n<\/ul>\n<p>Plus it has some helpful operators:<\/p>\n<ul>\n<li><code>%s!=%<\/code>, <code>%s!==%<\/code>, <code>%s+%<\/code>, <code>%s&lt;%<\/code>, <code>%s&lt;=%<\/code>, <code>%s==%<\/code>, <code>%s===% %s&gt;%<\/code>, <code>%s&gt;=%<\/code>, <code>%stri!=%<\/code>, <code>%stri!==%<\/code>, <code>%stri+%<\/code>, <code>%stri&lt;%<\/code>, <code>%stri&lt;=%<\/code>, <code>%stri==%<\/code>, <code>%stri===%<\/code>, <code>%stri&gt;%<\/code>, <code>%stri&gt;=%<\/code><\/li>\n<\/ul>\n<p>Of those, <code>%s+%<\/code> is ++handy for string concatenation.<\/p>\n<p>Prior to <code>readr<\/code>, these were my go-to line\/raw readers\/writer: <code>stri_read_raw<\/code>, <code>stri_read_lines<\/code>, and <code>stri_write_lines<\/code>.<\/p>\n<p>It also handles gnarly character encoding operations in a cross-platform, predictable manner.<\/p>\n<h3>FIN<\/h3>\n<p>To do a full comparison justice would have required writing a mini-book which is something I can&#8217;t spare cycles on, so my primary goals were to make sure folks knew <code>stringr<\/code> wrapped <code>stringi<\/code> and to show that <code>stringi<\/code> has much more to offer than you probably knew. If you start to get hooked on some of the more &#8220;fun&#8221; or utilitarian functions in <code>stringi<\/code> it&#8217;s probably worth switching to it. If string ops are ancillary operations to you and you normally work in regex-land, then you&#8217;re not missing out on anything and can save a few keystrokes here and there by using <code>stringr<\/code>.<\/p>\n<p>Comments are extremely encouraged for this post as I&#8217;m curious if you know about <code>stringi<\/code> before and when\/where\/how you use it vs <code>stringr<\/code> (or, why you don&#8217;t).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I made a promise to someone that my next blog would be about stringi vs stringr and I intend to keep said promise. stringr and stringi do &#8220;string operations&#8221;: find, replace, match, extract, convert, transform, etc. The stringr package is now part of the tidyverse and is 100% focused on string processing and is pretty [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[91],"tags":[810],"class_list":["post-4980","post","type-post","status-publish","format-standard","hentry","category-r","tag-post"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Strung Out On String Ops - A Brief Comparison of stringi and stringr - rud.is<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Strung Out On String Ops - A Brief Comparison of stringi and stringr - rud.is\" \/>\n<meta property=\"og:description\" content=\"I made a promise to someone that my next blog would be about stringi vs stringr and I intend to keep said promise. stringr and stringi do &#8220;string operations&#8221;: find, replace, match, extract, convert, transform, etc. The stringr package is now part of the tidyverse and is 100% focused on string processing and is pretty [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/\" \/>\n<meta property=\"og:site_name\" content=\"rud.is\" \/>\n<meta property=\"article:published_time\" content=\"2017-02-06T05:11:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-03-07T22:24:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/rud.is\/b\/wp-content\/uploads\/2017\/02\/ct-1.png\" \/>\n<meta name=\"author\" content=\"hrbrmstr\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"hrbrmstr\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/02\\\/06\\\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/02\\\/06\\\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\\\/\"},\"author\":{\"name\":\"hrbrmstr\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"headline\":\"Strung Out On String Ops &#8211; A Brief Comparison of stringi and stringr\",\"datePublished\":\"2017-02-06T05:11:31+00:00\",\"dateModified\":\"2018-03-07T22:24:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/02\\\/06\\\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\\\/\"},\"wordCount\":693,\"commentCount\":7,\"publisher\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"image\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/02\\\/06\\\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2017\\\/02\\\/ct-1.png\",\"keywords\":[\"post\"],\"articleSection\":[\"R\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/02\\\/06\\\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/02\\\/06\\\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\\\/\",\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/02\\\/06\\\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\\\/\",\"name\":\"Strung Out On String Ops - A Brief Comparison of stringi and stringr - rud.is\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/02\\\/06\\\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/02\\\/06\\\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2017\\\/02\\\/ct-1.png\",\"datePublished\":\"2017-02-06T05:11:31+00:00\",\"dateModified\":\"2018-03-07T22:24:18+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/02\\\/06\\\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/02\\\/06\\\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/02\\\/06\\\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2017\\\/02\\\/ct-1.png?fit=1536%2C480&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2017\\\/02\\\/ct-1.png?fit=1536%2C480&ssl=1\",\"width\":1536,\"height\":480},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2017\\\/02\\\/06\\\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/rud.is\\\/b\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Strung Out On String Ops &#8211; A Brief Comparison of stringi and stringr\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#website\",\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/\",\"name\":\"rud.is\",\"description\":\"&quot;In God we trust. All others must bring data&quot;\",\"publisher\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/rud.is\\\/b\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\",\"name\":\"hrbrmstr\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"width\":460,\"height\":460,\"caption\":\"hrbrmstr\"},\"logo\":{\"@id\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\"},\"description\":\"Don't look at me\u2026I do what he does \u2014 just slower. #rstats avuncular \u2022 ?Resistance Fighter \u2022 Cook \u2022 Christian \u2022 [Master] Chef des Donn\u00e9es de S\u00e9curit\u00e9 @ @rapid7\",\"sameAs\":[\"http:\\\/\\\/rud.is\"],\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/author\\\/hrbrmstr\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Strung Out On String Ops - A Brief Comparison of stringi and stringr - rud.is","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/","og_locale":"en_US","og_type":"article","og_title":"Strung Out On String Ops - A Brief Comparison of stringi and stringr - rud.is","og_description":"I made a promise to someone that my next blog would be about stringi vs stringr and I intend to keep said promise. stringr and stringi do &#8220;string operations&#8221;: find, replace, match, extract, convert, transform, etc. The stringr package is now part of the tidyverse and is 100% focused on string processing and is pretty [&hellip;]","og_url":"https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/","og_site_name":"rud.is","article_published_time":"2017-02-06T05:11:31+00:00","article_modified_time":"2018-03-07T22:24:18+00:00","og_image":[{"url":"https:\/\/rud.is\/b\/wp-content\/uploads\/2017\/02\/ct-1.png","type":"","width":"","height":""}],"author":"hrbrmstr","twitter_card":"summary_large_image","twitter_misc":{"Written by":"hrbrmstr","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/#article","isPartOf":{"@id":"https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/"},"author":{"name":"hrbrmstr","@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"headline":"Strung Out On String Ops &#8211; A Brief Comparison of stringi and stringr","datePublished":"2017-02-06T05:11:31+00:00","dateModified":"2018-03-07T22:24:18+00:00","mainEntityOfPage":{"@id":"https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/"},"wordCount":693,"commentCount":7,"publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"image":{"@id":"https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/#primaryimage"},"thumbnailUrl":"https:\/\/rud.is\/b\/wp-content\/uploads\/2017\/02\/ct-1.png","keywords":["post"],"articleSection":["R"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/","url":"https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/","name":"Strung Out On String Ops - A Brief Comparison of stringi and stringr - rud.is","isPartOf":{"@id":"https:\/\/rud.is\/b\/#website"},"primaryImageOfPage":{"@id":"https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/#primaryimage"},"image":{"@id":"https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/#primaryimage"},"thumbnailUrl":"https:\/\/rud.is\/b\/wp-content\/uploads\/2017\/02\/ct-1.png","datePublished":"2017-02-06T05:11:31+00:00","dateModified":"2018-03-07T22:24:18+00:00","breadcrumb":{"@id":"https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/#primaryimage","url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/02\/ct-1.png?fit=1536%2C480&ssl=1","contentUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/02\/ct-1.png?fit=1536%2C480&ssl=1","width":1536,"height":480},{"@type":"BreadcrumbList","@id":"https:\/\/rud.is\/b\/2017\/02\/06\/strung-out-on-string-ops-a-brief-comparison-of-stringi-and-stringr\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/rud.is\/b\/"},{"@type":"ListItem","position":2,"name":"Strung Out On String Ops &#8211; A Brief Comparison of stringi and stringr"}]},{"@type":"WebSite","@id":"https:\/\/rud.is\/b\/#website","url":"https:\/\/rud.is\/b\/","name":"rud.is","description":"&quot;In God we trust. All others must bring data&quot;","publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/rud.is\/b\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886","name":"hrbrmstr","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","contentUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","width":460,"height":460,"caption":"hrbrmstr"},"logo":{"@id":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1"},"description":"Don't look at me\u2026I do what he does \u2014 just slower. #rstats avuncular \u2022 ?Resistance Fighter \u2022 Cook \u2022 Christian \u2022 [Master] Chef des Donn\u00e9es de S\u00e9curit\u00e9 @ @rapid7","sameAs":["http:\/\/rud.is"],"url":"https:\/\/rud.is\/b\/author\/hrbrmstr\/"}]}},"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p23idr-1ik","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":3498,"url":"https:\/\/rud.is\/b\/2015\/07\/09\/faceted-world-population-by-income-choropleths-in-ggplot\/","url_meta":{"origin":4980,"position":0},"title":"Faceted &#8220;World Population by Income&#8221; Choropleths in ggplot","author":"hrbrmstr","date":"2015-07-09","format":false,"excerpt":"Poynter did a nice interactive piece on world population by income (i.e. \"How Many Live on How Much, and Where\"). I'm always on the lookout for optimized shapefiles and clean data (I'm teaching a data science certificate program starting this Fall) and the speed of the site load and the\u2026","rel":"","context":"In &quot;cartography&quot;","block_context":{"text":"cartography","link":"https:\/\/rud.is\/b\/category\/cartography\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":13391,"url":"https:\/\/rud.is\/b\/2022\/04\/04\/update-on-esc-pos-package-work\/","url_meta":{"origin":4980,"position":1},"title":"Update On ESC\/POS Package Work","author":"hrbrmstr","date":"2022-04-04","format":false,"excerpt":"The morning before work was super productive and there is a nigh-complete DSL for ESC\/POS commands along with the ability to just print {ggplot2}\/{grid} object. I changed the package name to {escpos} since it is no longer just plot object focused, and the DSL looks a bit like this: library(stringi)\u2026","rel":"","context":"In &quot;R&quot;","block_context":{"text":"R","link":"https:\/\/rud.is\/b\/category\/r\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":12804,"url":"https:\/\/rud.is\/b\/2020\/08\/07\/quick-hit-comparison-of-whole-file-reading-methods\/","url_meta":{"origin":4980,"position":2},"title":"Quick Hit: Comparison of &#8220;Whole File Reading&#8221; Methods","author":"hrbrmstr","date":"2020-08-07","format":false,"excerpt":"(This is part 1 of n posts using this same data; n will likely be 2-3, and the posts are more around optimization than anything else.) I recently had to analyze HTTP response headers (generated by a HEAD request) from around 74,000 sites (each response stored in a text file).\u2026","rel":"","context":"In &quot;R&quot;","block_context":{"text":"R","link":"https:\/\/rud.is\/b\/category\/r\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10834,"url":"https:\/\/rud.is\/b\/2018\/05\/29\/the-fix-is-in-finding-infix-functions-inside-contributed-r-package-utilities-files\/","url_meta":{"origin":4980,"position":3},"title":"The Fix Is In: Finding infix functions inside contributed R package &#8220;utilities&#8221; files","author":"hrbrmstr","date":"2018-05-29","format":false,"excerpt":"Regular readers will recall the \"utility belt\" post from back in April of this year. This is a follow-up to a request made asking for a list of all the % infix functions in those files. We're going to: collect up all of the sources parse them find all the\u2026","rel":"","context":"In &quot;R&quot;","block_context":{"text":"R","link":"https:\/\/rud.is\/b\/category\/r\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":11894,"url":"https:\/\/rud.is\/b\/2019\/02\/09\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\/","url_meta":{"origin":4980,"position":4},"title":"Quick Hit: Speeding Up a Slow\/Mundane Task with a Little Rcpp","author":"hrbrmstr","date":"2019-02-09","format":false,"excerpt":"Over at $DAYJOB's blog I've queued up a post that shows how to use our new ropendata? package to work with our Open Data portal's API. I'm not super-sure when it's going to be posted so keep an RSS reader fixed on https:\/\/blog.rapid7.com\/ if you're interested in seeing it (I\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/rud.is\/b\/category\/c\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3127,"url":"https:\/\/rud.is\/b\/2014\/11\/26\/visualizing-historical-most-likely-first-snowfall-dates-for-u-s-regions\/","url_meta":{"origin":4980,"position":5},"title":"Visualizing Historical &#038; Most-likely First Snowfall Dates for U.S. Regions","author":"hrbrmstr","date":"2014-11-26","format":false,"excerpt":"UPDATE: You can now run this as a local Shiny app by entering shiny::runGist(\"95ec24c1b0cb433a76a5\", launch.browser=TRUE) at an R prompt (provided all the dependent libraries (below) are installed) or use it interactively over at Shiny Apps. The impending arrival of the first real snowfall of the year in my part of\u2026","rel":"","context":"In &quot;Charts &amp; Graphs&quot;","block_context":{"text":"Charts &amp; Graphs","link":"https:\/\/rud.is\/b\/category\/charts-graphs\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/4980","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/comments?post=4980"}],"version-history":[{"count":0,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/4980\/revisions"}],"wp:attachment":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/media?parent=4980"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/categories?post=4980"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/tags?post=4980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}