

{"id":12917,"date":"2021-01-26T22:19:38","date_gmt":"2021-01-27T03:19:38","guid":{"rendered":"https:\/\/rud.is\/b\/?p=12917"},"modified":"2021-01-26T22:19:38","modified_gmt":"2021-01-27T03:19:38","slug":"making-it-easier-to-experiment-with-compiled-swift-code-in-r","status":"publish","type":"post","link":"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/","title":{"rendered":"Making It Easier To Experiment With Compiled Swift Code In R"},"content":{"rendered":"<p>The <a href=\"https:\/\/rud.is\/b\/2021\/01\/23\/swiftr-switcheroo-calling-compiled-swift-from-r\/\">past<\/a> <a href=\"https:\/\/rud.is\/b\/2021\/01\/24\/calling-compiled-swift-from-r-part-2\/\">two<\/a> posts have (lightly) introduced how to use compiled Swift code in R, but they&#8217;ve involved a bunch of &#8220;scary&#8221; command line machinations and incantations.<\/p>\n<p>One feature of {Rcpp} I&#8217;ve always ? is the <code>cppFunction()<\/code> (&#8220;r-lib&#8221; zealots have a similar <code>cpp11::cpp_function()<\/code>) which lets one experiment with C[++] code in R with as little friction as possible. To make it easier to start experimenting with Swift, I&#8217;ve built an <em>extremely fragile<\/em> <code>swift_function()<\/code> in <a href=\"https:\/\/git.rud.is\/hrbrmstr\/swiftr\">{swiftr}<\/a> that intends to replicate this functionality. Explaining it will be easier with an example.<\/p>\n<h3>Reading Property Lists in R With Swift<\/h3>\n<p>macOS relies <em>heavily<\/em> on <a href=\"https:\/\/en.wikipedia.org\/wiki\/Property_list\">property lists<\/a> for many, many things. These can be plain text (XML) or binary files and there are command-line tools and Python libraries (usable via {reticulate}) that can read them along with the good &#8216;ol <code>XML::readKeyValueDB()<\/code>. We&#8217;re going to create a Swift function to read property lists and return JSON which we can use back in R via {jsonlite}.<\/p>\n<p>This time around there&#8217;s no need to create extra files, just install {swiftr} and your favorite R IDE and enter the following (expository is after the code):<\/p>\n<pre><code class=\"language-r\">library(swiftr)\n\nswift_function(\n  code = '\n\nfunc ignored() {\n  print(\"\"\"\nthis will be ignored by swift_function() but you could use private\nfunctions as helpers for the main public Swift function which will be \nmade available to R.\n\"\"\")\n}  \n\n@_cdecl (\"read_plist\")\npublic func read_plist(path: SEXP) -&gt; SEXP {\n\n  var out: SEXP = R_NilValue\n\n  do {\n    \/\/ read in the raw plist\n    let plistRaw = try Data(contentsOf: URL(fileURLWithPath: String(cString: R_CHAR(STRING_ELT(path, 0)))))\n\n    \/\/ convert it to a PropertyList  \n    let plist = try PropertyListSerialization.propertyList(from: plistRaw, options: [], format: nil) as! [String:Any]\n\n    \/\/ serialize it to JSON\n    let jsonData = try JSONSerialization.data(withJSONObject: plist , options: .prettyPrinted)\n\n    \/\/ setup the JSON string return\n    String(data: jsonData, encoding: .utf8)?.withCString { \n      cstr in out = Rf_mkString(cstr) \n    }\n\n  } catch {\n    debugPrint(\"\\\\(error)\")\n  }\n\n  return(out)\n\n}\n')\n<\/code><\/pre>\n<p>This new <code>swift_function()<\/code> function \u2014 for the moment (the API is absolutely going to change) \u2014 is defined as:<\/p>\n<pre><code class=\"language-r\">swift_function(\n  code,\n  env = globalenv(),\n  imports = c(\"Foundation\"),\n  cache_dir = tempdir()\n)\n<\/code><\/pre>\n<p>where:<\/p>\n<ul>\n<li><code>code<\/code> is a length 1 character vector of Swift code<\/li>\n<li><code>env<\/code> is the environment to expose the function in (defaults to the global environment)<\/li>\n<li><code>imports<\/code> is a character vector of any extra Swift frameworks that need to be <code>import<\/code>ed<\/li>\n<li><code>cache_dir<\/code> is where all the temporary files will be created and compiled <code>dynlib<\/code> will be stored. It defaults to a temporary directory so specify your own directory (that exists) if you want to keep the files around after you close the R session<\/li>\n<\/ul>\n<p>Folks familiar with <code>cppFunction()<\/code> will notice some (on-purpose) similarities.<\/p>\n<p>The function expects you to expose only <em>one<\/em> <code>public<\/code> Swift function which also (for the moment) needs to have the <code>@_cdecl<\/code> decorator before it. You can have as many other valid Swift helper functions as you like, but are restricted to one function that will be turned into an R function automagically.<\/p>\n<p>In this example, <code>swift_function()<\/code> will see <code>public func read_plist(path: SEXP) -&gt; SEXP {<\/code> and be able to identify<\/p>\n<ul>\n<li>the function name (<code>read_plist<\/code>)<\/li>\n<li>the number of parameters (they all need to be <code>SEXP<\/code>, for now)<\/li>\n<li>the names of the parameters<\/li>\n<\/ul>\n<p>A complete source file with all the <code>import<\/code>s will be created and a pre-built bridging header (which comes along for the ride with {swiftr}) will be included in the compilation step and a <code>dylib<\/code> will be built and loaded into the R session. Finally, an R function that wraps a <code>.Call()<\/code> will be created and will have the function name of the Swift function as well as all the parameter names (if any).<\/p>\n<p>In the case of our example, above, the built R function is:<\/p>\n<pre><code class=\"language-r\">function(path) {\n  .Call(\"read_plist\", path)\n}\n<\/code><\/pre>\n<p>There&#8217;s a good chance you&#8217;re using RStudio, so we can test this with it&#8217;s property list, or you can substitute any other application&#8217;s property list (or any <code>.plist<\/code> you have) to test this out:<\/p>\n<pre><code class=\"language-r\">read_plist(\"\/Applications\/RStudio.app\/Contents\/Info.plist\") %&gt;% \n  jsonlite::fromJSON() %&gt;% \n  str(1)\n## List of 32\n##  $ NSPrincipalClass                     : chr \"NSApplication\"\n##  $ NSCameraUsageDescription             : chr \"R wants to access the camera.\"\n##  $ CFBundleIdentifier                   : chr \"org.rstudio.RStudio\"\n##  $ CFBundleShortVersionString           : chr \"1.4.1093-1\"\n##  $ NSBluetoothPeripheralUsageDescription: chr \"R wants to access bluetooth.\"\n##  $ NSRemindersUsageDescription          : chr \"R wants to access the reminders.\"\n##  $ NSAppleEventsUsageDescription        : chr \"R wants to run AppleScript.\"\n##  $ NSHighResolutionCapable              : logi TRUE\n##  $ LSRequiresCarbon                     : logi TRUE\n##  $ NSPhotoLibraryUsageDescription       : chr \"R wants to access the photo library.\"\n##  $ CFBundleGetInfoString                : chr \"RStudio 1.4.1093-1, \u00a9 2009-2020 RStudio, PBC\"\n##  $ NSLocationWhenInUseUsageDescription  : chr \"R wants to access location information.\"\n##  $ CFBundleInfoDictionaryVersion        : chr \"6.0\"\n##  $ NSSupportsAutomaticGraphicsSwitching : logi TRUE\n##  $ CSResourcesFileMapped                : logi TRUE\n##  $ CFBundleVersion                      : chr \"1.4.1093-1\"\n##  $ OSAScriptingDefinition               : chr \"RStudio.sdef\"\n##  $ CFBundleLongVersionString            : chr \"1.4.1093-1\"\n##  $ CFBundlePackageType                  : chr \"APPL\"\n##  $ NSContactsUsageDescription           : chr \"R wants to access contacts.\"\n##  $ NSCalendarsUsageDescription          : chr \"R wants to access calendars.\"\n##  $ NSMicrophoneUsageDescription         : chr \"R wants to access the microphone.\"\n##  $ CFBundleDocumentTypes                :'data.frame':  16 obs. of  8 variables:\n##  $ NSPhotoLibraryAddUsageDescription    : chr \"R wants write access to the photo library.\"\n##  $ NSAppleScriptEnabled                 : logi TRUE\n##  $ CFBundleExecutable                   : chr \"RStudio\"\n##  $ CFBundleSignature                    : chr \"Rstd\"\n##  $ NSHumanReadableCopyright             : chr \"RStudio 1.4.1093-1, \u00a9 2009-2020 RStudio, PBC\"\n##  $ CFBundleName                         : chr \"RStudio\"\n##  $ LSApplicationCategoryType            : chr \"public.app-category.developer-tools\"\n##  $ CFBundleIconFile                     : chr \"RStudio.icns\"\n##  $ CFBundleDevelopmentRegion            : chr \"English\"\n<\/code><\/pre>\n<h3>FIN<\/h3>\n<p>A <code>source_swift()<\/code> function is on the horizon as is adding a ton of checks\/validations to <code>swift_function()<\/code>. I&#8217;ll likely be adding some of the SEXP and R Swift utility functions I&#8217;ve demonstrated in <a href=\"https:\/\/rud.is\/books\/swiftr\/\">the [unfinished] book<\/a> to make it fairly painless to interface Swift and R code in this new and forthcoming function.<\/p>\n<p>As usual, kick the tyres, submit feature requests and bugs in any forum that&#8217;s comfortable and stay strong, wear a ?, and socially distanced when out and about.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The past two posts have (lightly) introduced how to use compiled Swift code in R, but they&#8217;ve involved a bunch of &#8220;scary&#8221; command line machinations and incantations. One feature of {Rcpp} I&#8217;ve always ? is the cppFunction() (&#8220;r-lib&#8221; zealots have a similar cpp11::cpp_function()) which lets one experiment with C[++] code in R with as little [&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":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":""},"categories":[780,91,830],"tags":[],"class_list":["post-12917","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.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Making It Easier To Experiment With Compiled Swift Code In R - 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\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Making It Easier To Experiment With Compiled Swift Code In R - rud.is\" \/>\n<meta property=\"og:description\" content=\"The past two posts have (lightly) introduced how to use compiled Swift code in R, but they&#8217;ve involved a bunch of &#8220;scary&#8221; command line machinations and incantations. One feature of {Rcpp} I&#8217;ve always ? is the cppFunction() (&#8220;r-lib&#8221; zealots have a similar cpp11::cpp_function()) which lets one experiment with C[++] code in R with as little [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"rud.is\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-27T03:19:38+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=\"5 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\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/\"},\"author\":{\"name\":\"hrbrmstr\",\"@id\":\"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886\"},\"headline\":\"Making It Easier To Experiment With Compiled Swift Code In R\",\"datePublished\":\"2021-01-27T03:19:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/\"},\"wordCount\":579,\"commentCount\":3,\"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\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/\",\"url\":\"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/\",\"name\":\"Making It Easier To Experiment With Compiled Swift Code In R - rud.is\",\"isPartOf\":{\"@id\":\"https:\/\/rud.is\/b\/#website\"},\"datePublished\":\"2021-01-27T03:19:38+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/rud.is\/b\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Making It Easier To Experiment With Compiled Swift Code In R\"}]},{\"@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":"Making It Easier To Experiment With Compiled Swift Code In R - 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\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/","og_locale":"en_US","og_type":"article","og_title":"Making It Easier To Experiment With Compiled Swift Code In R - rud.is","og_description":"The past two posts have (lightly) introduced how to use compiled Swift code in R, but they&#8217;ve involved a bunch of &#8220;scary&#8221; command line machinations and incantations. One feature of {Rcpp} I&#8217;ve always ? is the cppFunction() (&#8220;r-lib&#8221; zealots have a similar cpp11::cpp_function()) which lets one experiment with C[++] code in R with as little [&hellip;]","og_url":"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/","og_site_name":"rud.is","article_published_time":"2021-01-27T03:19:38+00:00","author":"hrbrmstr","twitter_card":"summary_large_image","twitter_misc":{"Written by":"hrbrmstr","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/#article","isPartOf":{"@id":"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/"},"author":{"name":"hrbrmstr","@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"headline":"Making It Easier To Experiment With Compiled Swift Code In R","datePublished":"2021-01-27T03:19:38+00:00","mainEntityOfPage":{"@id":"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/"},"wordCount":579,"commentCount":3,"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\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/","url":"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/","name":"Making It Easier To Experiment With Compiled Swift Code In R - rud.is","isPartOf":{"@id":"https:\/\/rud.is\/b\/#website"},"datePublished":"2021-01-27T03:19:38+00:00","breadcrumb":{"@id":"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/rud.is\/b\/"},{"@type":"ListItem","position":2,"name":"Making It Easier To Experiment With Compiled Swift Code In R"}]},{"@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-3ml","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":12917,"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":12878,"url":"https:\/\/rud.is\/b\/2021\/01\/16\/new-swiftr-chapter-up-building-an-r-backed-swiftui-macos-app\/","url_meta":{"origin":12917,"position":1},"title":"New SwiftR Chapter Up: Building an R-backed SwiftUI macOS App","author":"hrbrmstr","date":"2021-01-16","format":false,"excerpt":"Last week I introduced a new bookdown series on how to embed R into a macOS Swift application. The initial chapters focused on core concepts and showed how to build a macOS compiled, binary command line application that uses embedded R for some functionality. This week, a new chapter is\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":12866,"url":"https:\/\/rud.is\/b\/2021\/01\/04\/bringing-r-to-swift-on-macos\/","url_meta":{"origin":12917,"position":2},"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":12896,"url":"https:\/\/rud.is\/b\/2021\/01\/24\/calling-compiled-swift-from-r-part-2\/","url_meta":{"origin":12917,"position":3},"title":"Calling [Compiled] Swift from R: Part 2","author":"hrbrmstr","date":"2021-01-24","format":false,"excerpt":"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's machine learning libraries,\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":12438,"url":"https:\/\/rud.is\/b\/2019\/08\/22\/quick-hit-a-new-64-bit-swift-5-rswitch-app\/","url_meta":{"origin":12917,"position":4},"title":"Quick Hit: A new 64-bit Swift 5 RSwitch App","author":"hrbrmstr","date":"2019-08-22","format":false,"excerpt":"At the bottom of the R for macOS Developer's Page there's mention of an \"other binary\" called \"RSwitch\" that is \"a small GUI that allows you to switch between R versions quickly (if you have multiple versions of R framework installed).\" Said switching requires you to use the \"tar.gz\" versions\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":13026,"url":"https:\/\/rud.is\/b\/2021\/04\/14\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\/","url_meta":{"origin":12917,"position":5},"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":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/12917","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=12917"}],"version-history":[{"count":0,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/12917\/revisions"}],"wp:attachment":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/media?parent=12917"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/categories?post=12917"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/tags?post=12917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}