

{"id":12896,"date":"2021-01-24T08:26:59","date_gmt":"2021-01-24T13:26:59","guid":{"rendered":"https:\/\/rud.is\/b\/?p=12896"},"modified":"2021-01-25T09:04:28","modified_gmt":"2021-01-25T14:04:28","slug":"calling-compiled-swift-from-r-part-2","status":"publish","type":"post","link":"https:\/\/rud.is\/b\/2021\/01\/24\/calling-compiled-swift-from-r-part-2\/","title":{"rendered":"Calling [Compiled] Swift from R: Part 2"},"content":{"rendered":"<p>The <a href=\"https:\/\/rud.is\/b\/2021\/01\/23\/swiftr-switcheroo-calling-compiled-swift-from-r\/\">previous post<\/a> introduced the topic of how to compile Swift code for use in R using a useless, toy example. This one goes a bit further and makes a case for why one might want to do this by showing how to use one of Apple&#8217;s <a href=\"https:\/\/developer.apple.com\/machine-learning\/\">machine learning libraries<\/a>, specifically the <a href=\"https:\/\/developer.apple.com\/documentation\/naturallanguage\">Natural Language<\/a> one, focusing on <a href=\"https:\/\/developer.apple.com\/documentation\/naturallanguage\/identifying_parts_of_speech\">extracting parts of speech<\/a> from text.<\/p>\n<p>I made a <code>parts-of-speech<\/code> directory to keep the code self-contained. In it are two files. The first is <code>partsofspeech.swift<\/code> (<code>swiftc<\/code> seems to dislike dashes in names of library code and I dislike underscores):<\/p>\n<pre><code class=\"language-swift\">import NaturalLanguage\nimport CoreML\n\nextension Array where Element == String {\n  var SEXP: SEXP? {\n    let charVec = Rf_protect(Rf_allocVector(SEXPTYPE(STRSXP), count))\n    defer { Rf_unprotect(1) }\n    for (idx, elem) in enumerated() { SET_STRING_ELT(charVec, idx, Rf_mkChar(elem)) }\n    return(charVec)\n  }\n}\n\n@_cdecl (\"part_of_speech\")\npublic func part_of_speech(_ x: SEXP) -&gt; SEXP {\n\n  let text = String(cString: R_CHAR(STRING_ELT(x, 0)))\n  let tagger = NLTagger(tagSchemes: [.lexicalClass])\n\n  tagger.string = text\n\n  let options: NLTagger.Options = [.omitPunctuation, .omitWhitespace]\n\n  var txts = [String]()\n  var tags = [String]()\n\n  tagger.enumerateTags(in: text.startIndex..&lt;text.endIndex, unit: .word, scheme: .lexicalClass, options: options) { tag, tokenRange in\n    if let tag = tag {\n      txts.append(\"\\(text[tokenRange])\")\n      tags.append(\"\\(tag.rawValue)\")\n    }\n    return true\n  }\n\n  let out = Rf_protect(Rf_allocVector(SEXPTYPE(VECSXP), 2))\n  SET_VECTOR_ELT(out, 0, txts.SEXP)\n  SET_VECTOR_ELT(out, 1, tags.SEXP)\n  Rf_unprotect(1)\n\n  return(out!)\n}\n<\/code><\/pre>\n<p>The other is bridge code that seems to be the same for every one of these (or could be) so I&#8217;ve just named it <code>swift-r-glue.h<\/code> (it&#8217;s the same as the bridge code in the previous post):<\/p>\n<pre><code class=\"language-clike\">#define USE_RINTERNALS\n\n#include &lt;R.h&gt;\n#include &lt;Rinternals.h&gt;\n\nconst char* R_CHAR(SEXP x);\n<\/code><\/pre>\n<p>Let&#8217;s walk through the Swift code.<\/p>\n<p>We need to two <code>import<\/code>s:<\/p>\n<pre><code class=\"language-swift\">import NaturalLanguage\nimport CoreML\n<\/code><\/pre>\n<p>to make use of the NLP functionality provided by Apple.<\/p>\n<p>The following extension to the String Array class:<\/p>\n<pre><code class=\"language-swift\">extension Array where Element == String {\n  var SEXP: SEXP? {\n    let charVec = Rf_protect(Rf_allocVector(SEXPTYPE(STRSXP), count))\n    defer { Rf_unprotect(1) }\n    for (idx, elem) in enumerated() { SET_STRING_ELT(charVec, idx, Rf_mkChar(elem)) }\n    return(charVec)\n  }\n}\n<\/code><\/pre>\n<p>will reduce the amount of code we need to type later on to turn Swift String Arrays to R character vectors.<\/p>\n<p>The start of the function:<\/p>\n<pre><code class=\"language-swift\">@_cdecl (\"part_of_speech\")\npublic func part_of_speech(_ x: SEXP) -&gt; SEXP {\n<\/code><\/pre>\n<p>tells <code>swiftc<\/code> to make this a C-compatible call and notes that the function takes one parameter (in this case, it&#8217;s expecting a length 1 character vector) and returns an R-compatible value (which will be a <code>list<\/code> that we&#8217;ll turn into a <code>data.frame<\/code> in R just for brevity).<\/p>\n<p>The following sets up our inputs and outputs:<\/p>\n<pre><code class=\"language-swift\">  let text = String(cString: R_CHAR(STRING_ELT(x, 0)))\n  let tagger = NLTagger(tagSchemes: [.lexicalClass])\n\n  tagger.string = text\n\n  let options: NLTagger.Options = [.omitPunctuation, .omitWhitespace]\n\n  var txts = [String]()\n  var tags = [String]()\n<\/code><\/pre>\n<p>We convert the passed-in parameter to a Swift String, initialize the NLP tagger, and setup two arrays to hold the results (sentence component in <code>txts<\/code> and the part of speech that component is in <code>tags<\/code>).<\/p>\n<p>The following code is mostly straight from Apple and (inefficiently) populates the previous two arrays:<\/p>\n<pre><code class=\"language-swift\"><br \/>  tagger.enumerateTags(in: text.startIndex..&lt;text.endIndex, unit: .word, scheme: .lexicalClass, options: options) { tag, tokenRange in\n    if let tag = tag {\n      txts.append(\"\\(text[tokenRange])\")\n      tags.append(\"\\(tag.rawValue)\")\n    }\n    return true\n  }\n<\/code><\/pre>\n<p>Finally, we use the Swift-R bridge to make a <code>list<\/code> much like one would in C:<\/p>\n<pre><code class=\"language-swift\"><br \/>  let out = Rf_protect(Rf_allocVector(SEXPTYPE(VECSXP), 2))\n  SET_VECTOR_ELT(out, 0, txts.SEXP)\n  SET_VECTOR_ELT(out, 1, tags.SEXP)\n  Rf_unprotect(1)\n\n  return(out!)\n<\/code><\/pre>\n<p>To get a shared library we can use from R, we just need to compile this like last time:<\/p>\n<pre><code class=\"language-bash\">swiftc \\\n  -I \/Library\/Frameworks\/R.framework\/Headers \\\n  -F\/Library\/Frameworks \\\n  -framework R \\\n  -import-objc-header swift-r-glue.h \\\n  -emit-library \\\n  partsofspeech.swift\n<\/code><\/pre>\n<p>Let&#8217;s run that on some text! First, we&#8217;ll load the new shared library into R:<\/p>\n<pre><code class=\"language-r\">dyn.load(\"libpartsofspeech.dylib\")\n<\/code><\/pre>\n<p>Next, we&#8217;ll make a wrapper function to avoid messy <code>.Call(\u2026)<\/code>s and to make a <code>data.frame<\/code>:<\/p>\n<pre><code class=\"language-r\">parts_of_speech &lt;- function(x) {\n  res &lt;- .Call(\"part_of_speech\", x)  \n  as.data.frame(stats::setNames(res, c(\"name\", \"tag\")))\n}\n<\/code><\/pre>\n<p>Finally, let&#8217;s try this on some text!<\/p>\n<pre><code class=\"language-r\">tibble::as_tibble(\n  parts_of_speech(paste0(c(\n\"The comm wasn't working. Feeling increasingly ridiculous, he pushed\",\n\"the button for the 1MC channel several more times. Nothing. He opened\",\n\"his eyes and saw that all the lights on the panel were out. Then he\",\n\"turned around and saw that the lights on the refrigerator and the\",\n\"ovens were out. It wasn\u2019t just the coffeemaker; the entire galley was\",\n\"in open revolt. Holden looked at the ship name, Rocinante, newly\",\n\"stenciled onto the galley wall, and said, Baby, why do you hurt me\",\n\"when I love you so much?\"\n  ), collapse = \" \"))\n)\n## # A tibble: 92 x 2\n##    name         tag\n##    &lt;chr&gt;        &lt;chr&gt;\n##  1 The          Determiner\n##  2 comm         Noun\n##  3 was          Verb\n##  4 n't          Adverb\n##  5 working      Verb\n##  6 Feeling      Verb\n##  7 increasingly Adverb\n##  8 ridiculous   Adjective\n##  9 he           Pronoun\n## 10 pushed       Verb\n## # \u2026 with 82 more rows\n<\/code><\/pre>\n<h3>FIN<\/h3>\n<p>If you&#8217;re playing along at home, try adding a function to this Swift file that uses Apple&#8217;s <a href=\"https:\/\/developer.apple.com\/documentation\/naturallanguage\/identifying_people_places_and_organizations\">entity tagger<\/a>.<\/p>\n<p>The next installment of this topic will be how to wrap all this into a package (then all these examples get tweaked and go into <a href=\"https:\/\/rud.is\/books\/swiftr\/\">the tome<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The previous post introduced the topic of how to compile Swift code for use in R using a useless, toy example. This one goes a bit further and makes a case for why one might want to do this by showing how to use one of Apple&#8217;s machine learning libraries, specifically the Natural Language one, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_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":"","jetpack_post_was_ever_published":false},"categories":[780,91,830],"tags":[],"class_list":["post-12896","post","type-post","status-publish","format-standard","hentry","category-macos","category-r","category-swift"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Calling [Compiled] Swift from R: Part 2 - 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\/2021\/01\/24\/calling-compiled-swift-from-r-part-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Calling [Compiled] Swift from R: Part 2 - rud.is\" \/>\n<meta property=\"og:description\" content=\"The previous post introduced the topic of how to compile Swift code for use in R using a useless, toy example. This one goes a bit further and makes a case for why one might want to do this by showing how to use one of Apple&#8217;s machine learning libraries, specifically the Natural Language one, [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rud.is\/b\/2021\/01\/24\/calling-compiled-swift-from-r-part-2\/\" \/>\n<meta property=\"og:site_name\" content=\"rud.is\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-24T13:26:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-01-25T14:04:28+00:00\" \/>\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\\\/2021\\\/01\\\/24\\\/calling-compiled-swift-from-r-part-2\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2021\\\/01\\\/24\\\/calling-compiled-swift-from-r-part-2\\\/\"},\"author\":{\"name\":\"hrbrmstr\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"headline\":\"Calling [Compiled] Swift from R: Part 2\",\"datePublished\":\"2021-01-24T13:26:59+00:00\",\"dateModified\":\"2021-01-25T14:04:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2021\\\/01\\\/24\\\/calling-compiled-swift-from-r-part-2\\\/\"},\"wordCount\":417,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"articleSection\":[\"macOS\",\"R\",\"Swift\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2021\\\/01\\\/24\\\/calling-compiled-swift-from-r-part-2\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2021\\\/01\\\/24\\\/calling-compiled-swift-from-r-part-2\\\/\",\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/2021\\\/01\\\/24\\\/calling-compiled-swift-from-r-part-2\\\/\",\"name\":\"Calling [Compiled] Swift from R: Part 2 - rud.is\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#website\"},\"datePublished\":\"2021-01-24T13:26:59+00:00\",\"dateModified\":\"2021-01-25T14:04:28+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2021\\\/01\\\/24\\\/calling-compiled-swift-from-r-part-2\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2021\\\/01\\\/24\\\/calling-compiled-swift-from-r-part-2\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2021\\\/01\\\/24\\\/calling-compiled-swift-from-r-part-2\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/rud.is\\\/b\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Calling [Compiled] Swift from R: Part 2\"}]},{\"@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":"Calling [Compiled] Swift from R: Part 2 - 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\/2021\/01\/24\/calling-compiled-swift-from-r-part-2\/","og_locale":"en_US","og_type":"article","og_title":"Calling [Compiled] Swift from R: Part 2 - rud.is","og_description":"The previous post introduced the topic of how to compile Swift code for use in R using a useless, toy example. This one goes a bit further and makes a case for why one might want to do this by showing how to use one of Apple&#8217;s machine learning libraries, specifically the Natural Language one, [&hellip;]","og_url":"https:\/\/rud.is\/b\/2021\/01\/24\/calling-compiled-swift-from-r-part-2\/","og_site_name":"rud.is","article_published_time":"2021-01-24T13:26:59+00:00","article_modified_time":"2021-01-25T14:04:28+00:00","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\/2021\/01\/24\/calling-compiled-swift-from-r-part-2\/#article","isPartOf":{"@id":"https:\/\/rud.is\/b\/2021\/01\/24\/calling-compiled-swift-from-r-part-2\/"},"author":{"name":"hrbrmstr","@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"headline":"Calling [Compiled] Swift from R: Part 2","datePublished":"2021-01-24T13:26:59+00:00","dateModified":"2021-01-25T14:04:28+00:00","mainEntityOfPage":{"@id":"https:\/\/rud.is\/b\/2021\/01\/24\/calling-compiled-swift-from-r-part-2\/"},"wordCount":417,"commentCount":1,"publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"articleSection":["macOS","R","Swift"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/rud.is\/b\/2021\/01\/24\/calling-compiled-swift-from-r-part-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/rud.is\/b\/2021\/01\/24\/calling-compiled-swift-from-r-part-2\/","url":"https:\/\/rud.is\/b\/2021\/01\/24\/calling-compiled-swift-from-r-part-2\/","name":"Calling [Compiled] Swift from R: Part 2 - rud.is","isPartOf":{"@id":"https:\/\/rud.is\/b\/#website"},"datePublished":"2021-01-24T13:26:59+00:00","dateModified":"2021-01-25T14:04:28+00:00","breadcrumb":{"@id":"https:\/\/rud.is\/b\/2021\/01\/24\/calling-compiled-swift-from-r-part-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rud.is\/b\/2021\/01\/24\/calling-compiled-swift-from-r-part-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/rud.is\/b\/2021\/01\/24\/calling-compiled-swift-from-r-part-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/rud.is\/b\/"},{"@type":"ListItem","position":2,"name":"Calling [Compiled] Swift from R: Part 2"}]},{"@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-3m0","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":12891,"url":"https:\/\/rud.is\/b\/2021\/01\/23\/swiftr-switcheroo-calling-compiled-swift-from-r\/","url_meta":{"origin":12896,"position":0},"title":"SwiftR Switcheroo: Calling [Compiled] Swift from R!","author":"hrbrmstr","date":"2021-01-23","format":false,"excerpt":"I've been on a Swift + R bender for a while now, but have been envious of the pure macOS\/iOS (et al) folks who get to use Apple's seriously ++good machine learning libraries, which are even more robust on the new M1 hardware (it's cool having hardware components dedicated to\u2026","rel":"","context":"In &quot;macOS&quot;","block_context":{"text":"macOS","link":"https:\/\/rud.is\/b\/category\/macos\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":12917,"url":"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/","url_meta":{"origin":12896,"position":1},"title":"Making It Easier To Experiment With Compiled Swift Code In R","author":"hrbrmstr","date":"2021-01-26","format":false,"excerpt":"The past two posts have (lightly) introduced how to use compiled Swift code in R, but they've involved a bunch of \"scary\" command line machinations and incantations. One feature of {Rcpp} I've always ? is the cppFunction() (\"r-lib\" zealots have a similar cpp11::cpp_function()) which lets one experiment with C[++] code\u2026","rel":"","context":"In &quot;macOS&quot;","block_context":{"text":"macOS","link":"https:\/\/rud.is\/b\/category\/macos\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":13026,"url":"https:\/\/rud.is\/b\/2021\/04\/14\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\/","url_meta":{"origin":12896,"position":2},"title":"Avoiding The mdls Command Line Round Trip With swiftr::swift_function()","author":"hrbrmstr","date":"2021-04-14","format":false,"excerpt":"The last post showed how to work with the macOS mdls command line XML output, but with {swiftr} we can avoid the command line round trip by bridging the low-level Spotlight API (which mdls uses) directly in R via Swift. If you've already played with {swiftr} before but were somewhat\u2026","rel":"","context":"In &quot;macOS&quot;","block_context":{"text":"macOS","link":"https:\/\/rud.is\/b\/category\/macos\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":13094,"url":"https:\/\/rud.is\/b\/2021\/05\/22\/a-swiftr-brief-interlude-while-awaiting-cdcfluview-cran-checks\/","url_meta":{"origin":12896,"position":3},"title":"A {swiftr} Brief Interlude While Awaiting {cdcfluview} CRAN Checks","author":"hrbrmstr","date":"2021-05-22","format":false,"excerpt":"My {cdcfluview} package started tossing erros on CRAN just over a week ago when the CDC added an extra parameter to one of the hidden API endpoints that the package wraps. After a fairly hectic set of days since said NOTE came, I had time this morning to poke at\u2026","rel":"","context":"In &quot;macOS&quot;","block_context":{"text":"macOS","link":"https:\/\/rud.is\/b\/category\/macos\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2021\/05\/signs.jpeg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2021\/05\/signs.jpeg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2021\/05\/signs.jpeg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":12866,"url":"https:\/\/rud.is\/b\/2021\/01\/04\/bringing-r-to-swift-on-macos\/","url_meta":{"origin":12896,"position":4},"title":"Bringing R to Swift on macOS","author":"hrbrmstr","date":"2021-01-04","format":false,"excerpt":"Over Christmas break I teased some screencaps: A more refined #rstats #swift \"SwiftR\" example. Simple Image view + some text views, a color picker and a button that runs R-in-Swift code (like {reticulate} does for Python in R)Note no ssd\/hd storage round-trip for the plot.Code snippet: https:\/\/t.co\/fWaHnztUgd pic.twitter.com\/y5m1I16tCB\u2014 Caliban's War\u2026","rel":"","context":"In &quot;Apple&quot;","block_context":{"text":"Apple","link":"https:\/\/rud.is\/b\/category\/apple\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":13039,"url":"https:\/\/rud.is\/b\/2021\/04\/24\/making-macos-universal-apps-with-universal-golang-static-libraries\/","url_meta":{"origin":12896,"position":5},"title":"Making macOS Universal Apps in Swift with Universal Golang Static Libraries","author":"hrbrmstr","date":"2021-04-24","format":false,"excerpt":"There are a plethora of amazingly useful Golang libraries, and it has been possible for quite some time to use Go libraries with Swift. The advent of the release of the new Apple Silicon\/M1\/arm64 architecture for macOS created the need for a new round of \"fat\"\/\"universal\" binaries and libraries to\u2026","rel":"","context":"In &quot;Go&quot;","block_context":{"text":"Go","link":"https:\/\/rud.is\/b\/category\/go\/"},"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\/12896","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=12896"}],"version-history":[{"count":11,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/12896\/revisions"}],"predecessor-version":[{"id":12914,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/12896\/revisions\/12914"}],"wp:attachment":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/media?parent=12896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/categories?post=12896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/tags?post=12896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}