

{"id":13026,"date":"2021-04-14T19:50:51","date_gmt":"2021-04-15T00:50:51","guid":{"rendered":"https:\/\/rud.is\/b\/?p=13026"},"modified":"2021-04-14T20:32:21","modified_gmt":"2021-04-15T01:32:21","slug":"avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function","status":"publish","type":"post","link":"https:\/\/rud.is\/b\/2021\/04\/14\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\/","title":{"rendered":"Avoiding The mdls Command Line Round Trip With swiftr::swift_function()"},"content":{"rendered":"<p>The <a href=\"https:\/\/rud.is\/b\/2021\/04\/13\/quick-hit-processing-macos-application-metadata-weirdly-fast-with-mdls-and-r\/\">last post<\/a> showed how to work with the macOS <code>mdls<\/code> command line XML output, but with <a href=\"https:\/\/rud.is\/b\/2021\/01\/26\/making-it-easier-to-experiment-with-compiled-swift-code-in-r\/\">{swiftr}<\/a> we can avoid the command line round trip by bridging the low-level Spotlight API (which <code>mdls<\/code> uses) directly in R via Swift.<\/p>\n<p>If you&#8217;ve already played with {swiftr} before but were somewhat annoyed at various boilerplate elements you&#8217;ve had to drag along with you every time you used <code>swift_function()<\/code> you&#8217;ll be pleased that I&#8217;ve added <em>some<\/em> <code>SEXP<\/code> conversion helpers to the {swiftr} package, so there&#8217;s less cruft when using <code>swift_function()<\/code>.<\/p>\n<p>Let&#8217;s add an R\u2194Swift bridge function to retrieve all available Spotlight attributes for a macOS file:<\/p>\n<pre><code class=\"language-r\">library(swiftr)\n\nswift_function('\n\n  \/\/ Add an extension to URL which will retrieve the spotlight \n  \/\/ attributes as an array of Swift Strings\n  extension URL {\n\n  var mdAttributes: [String]? {\n\n    get {\n      guard isFileURL else { return nil }\n      let item = MDItemCreateWithURL(kCFAllocatorDefault, self as CFURL)\n      let attrs = MDItemCopyAttributeNames(item)!\n      return(attrs as? [String])\n    }\n\n  }\n\n}\n\n@_cdecl (\"file_attrs\")\npublic func file_attrs(path: SEXP) -&gt; SEXP {\n\n  \/\/ Grab the attributres\n  let outAttr = URL(fileURLWithPath: String(path)!).mdAttributes!\n\n  \/\/ send them to R\n  return(outAttr.SEXP!)\n\n}\n')\n<\/code><\/pre>\n<p>And, then try it out:<\/p>\n<pre><code class=\"language-r\">fil &lt;-  \"\/Applications\/RStudio.app\"\n\nfile_attrs(fil)\n##  [1] \"kMDItemContentTypeTree\"                 \"kMDItemContentType\"                    \n##  [3] \"kMDItemPhysicalSize\"                    \"kMDItemCopyright\"                      \n##  [5] \"kMDItemAppStoreCategory\"                \"kMDItemKind\"                           \n##  [7] \"kMDItemDateAdded_Ranking\"               \"kMDItemDocumentIdentifier\"             \n##  [9] \"kMDItemContentCreationDate\"             \"kMDItemAlternateNames\"                 \n## [11] \"kMDItemContentModificationDate_Ranking\" \"kMDItemDateAdded\"                      \n## [13] \"kMDItemContentCreationDate_Ranking\"     \"kMDItemContentModificationDate\"        \n## [15] \"kMDItemExecutableArchitectures\"         \"kMDItemAppStoreCategoryType\"           \n## [17] \"kMDItemVersion\"                         \"kMDItemCFBundleIdentifier\"             \n## [19] \"kMDItemInterestingDate_Ranking\"         \"kMDItemDisplayName\"                    \n## [21] \"_kMDItemDisplayNameWithExtensions\"      \"kMDItemLogicalSize\"                    \n## [23] \"kMDItemUsedDates\"                       \"kMDItemLastUsedDate\"                   \n## [25] \"kMDItemLastUsedDate_Ranking\"            \"kMDItemUseCount\"                       \n## [27] \"kMDItemFSName\"                          \"kMDItemFSSize\"                         \n## [29] \"kMDItemFSCreationDate\"                  \"kMDItemFSContentChangeDate\"            \n## [31] \"kMDItemFSOwnerUserID\"                   \"kMDItemFSOwnerGroupID\"                 \n## [33] \"kMDItemFSNodeCount\"                     \"kMDItemFSInvisible\"                    \n## [35] \"kMDItemFSTypeCode\"                      \"kMDItemFSCreatorCode\"                  \n## [37] \"kMDItemFSFinderFlags\"                   \"kMDItemFSHasCustomIcon\"                \n## [39] \"kMDItemFSIsExtensionHidden\"             \"kMDItemFSIsStationery\"                 \n## [41] \"kMDItemFSLabel\"   \n<\/code><\/pre>\n<p>No <code>system()<\/code> (et al.) round trip!<\/p>\n<p>Now, lets make R\u2194Swift bridge function to retrieve the value of an attribute.<\/p>\n<p>Before we do that, let me be up-front that relying on <code>debugDescription<\/code> (which makes a string representation of a Swift object) is a terrible hack that I&#8217;m using just to make the example as short as possible. We should do far more error checking and then further check the type of the object coming from the Spotlight API call and return an R-compatible version of that type. This <code>mdAttr()<\/code> method will almost certainly break depending on the item being returned.<\/p>\n<pre><code class=\"language-r\">swift_function('\nextension URL {\n\n  \/\/ Add an extension to URL which will retrieve the spotlight \n  \/\/ attribute value as a String. This will almost certainly die \n  \/\/ under various value conditions.\n\n  func mdAttr(_ attr: String) -&gt; String? {\n    guard isFileURL else { return nil }\n    let item = MDItemCreateWithURL(kCFAllocatorDefault, self as CFURL)\n    return(MDItemCopyAttribute(item, attr as CFString).debugDescription!)\n  }\n\n}\n\n@_cdecl (\"file_attr\")\npublic func file_attr(path: SEXP, attr: SEXP) -&gt; SEXP {\n\n  \/\/ file path as Swift String\n  let xPath = String(cString: R_CHAR(Rf_asChar(path)))\n\n  \/\/ attribute we want as a Swift String\n  let xAttr = String(cString: R_CHAR(Rf_asChar(attr)))\n\n  \/\/ the Swift debug string value of the attribute\n  let outAttr = URL(fileURLWithPath: xPath).mdAttr(xAttr)\n\n  \/\/ returned as an R string\n  return(Rf_mkString(outAttr))\n}\n')\n<\/code><\/pre>\n<p>And try this out on some <em>carefully<\/em> selected attributes:<\/p>\n<pre><code class=\"language-r\">file_attr(fil, \"kMDItemDisplayName\")\n## [1] \"RStudio.app\"\n\nfile_attr(fil, \"kMDItemAppStoreCategory\")\n## [1] \"Developer Tools\"\n\nfile_attr(fil, \"kMDItemVersion\")\n## [1] \"1.4.1651\"\n<\/code><\/pre>\n<p>Note that if we try to get fancy and retrieve an attribute value that is something like an array of strings, it doesn&#8217;t work so well:<\/p>\n<pre><code class=\"language-r\">file_attr(fil, \"kMDItemExecutableArchitectures\")\n## [1] \"&lt;__NSSingleObjectArrayI 0x7fe1f6d19bf0&gt;(\\nx86_64\\n)\\n\"\n<\/code><\/pre>\n<p>Again, ideally, we&#8217;d make a small package wrapper vs use <code>swift_function()<\/code> for this in production, but I wanted to show how straightforward it can be to get access to some fun and potentially powerful features of macOS right in R with just a tiny bit of Swift glue code.<\/p>\n<p>Also, I hadn&#8217;t tried {swiftr} on the M1 Mini before and it seems I need to poke a bit to see what needs doing to get it to work properly in the arm64 RStudio <code>rsession<\/code>.<\/p>\n<h3>UPDATE (2021-04-14 a bit later)<\/h3>\n<p>It dawned on me that a minor tweak to the Swift <code>mdAttr()<\/code> function would make the method more resilient (but still hacky):<\/p>\n<pre><code class=\"language-swift\">  func mdAttr(_ attr: String) -&gt; String {\n    guard isFileURL else { return \"\" }\n    let item = MDItemCreateWithURL(kCFAllocatorDefault, self as CFURL)\n    let x = MDItemCopyAttribute(item, attr as CFString)\n    if (x == nil) {\n      return(\"\")\n    } else {\n      return(\"\\(x!)\")\n    }\n  }\n<\/code><\/pre>\n<p>Now we can (more) safely do something like this:<\/p>\n<pre><code class=\"language-r\">str(as.list(sapply(\n  file_attrs(fil),\n  function(attr) {\n    file_attr(fil, attr)\n  }\n)), 1)\n## List of 41\n##  $ kMDItemContentTypeTree                : chr \"(\\n    \\\"com.apple.application-bundle\\\",\\n    \\\"com.apple.application\\\",\\n    \\\"public.executable\\\",\\n    \\\"com\"| __truncated__\n##  $ kMDItemContentType                    : chr \"com.apple.application-bundle\"\n##  $ kMDItemPhysicalSize                   : chr \"767619072\"\n##  $ kMDItemCopyright                      : chr \"RStudio 1.4.1651, \u00a9 2009-2021 RStudio, PBC\"\n##  $ kMDItemAppStoreCategory               : chr \"Developer Tools\"\n##  $ kMDItemKind                           : chr \"Application\"\n##  $ kMDItemDateAdded_Ranking              : chr \"2021-04-09 00:00:00 +0000\"\n##  $ kMDItemDocumentIdentifier             : chr \"0\"\n##  $ kMDItemContentCreationDate            : chr \"2021-03-25 23:08:34 +0000\"\n##  $ kMDItemAlternateNames                 : chr \"(\\n    \\\"RStudio.app\\\"\\n)\"\n##  $ kMDItemContentModificationDate_Ranking: chr \"2021-03-25 00:00:00 +0000\"\n##  $ kMDItemDateAdded                      : chr \"2021-04-09 13:25:11 +0000\"\n##  $ kMDItemContentCreationDate_Ranking    : chr \"2021-03-25 00:00:00 +0000\"\n##  $ kMDItemContentModificationDate        : chr \"2021-03-25 23:08:34 +0000\"\n##  $ kMDItemExecutableArchitectures        : chr \"(\\n    \\\"x86_64\\\"\\n)\"\n##  $ kMDItemAppStoreCategoryType           : chr \"public.app-category.developer-tools\"\n##  $ kMDItemVersion                        : chr \"1.4.1651\"\n##  $ kMDItemCFBundleIdentifier             : chr \"org.rstudio.RStudio\"\n##  $ kMDItemInterestingDate_Ranking        : chr \"2021-04-15 00:00:00 +0000\"\n##  $ kMDItemDisplayName                    : chr \"RStudio.app\"\n##  $ _kMDItemDisplayNameWithExtensions     : chr \"RStudio.app\"\n##  $ kMDItemLogicalSize                    : chr \"763253198\"\n##  $ kMDItemUsedDates                      : chr \"(\\n    \\\"2021-03-26 04:00:00 +0000\\\",\\n    \\\"2021-03-30 04:00:00 +0000\\\",\\n    \\\"2021-04-02 04:00:00 +0000\\\",\\n\"| __truncated__\n##  $ kMDItemLastUsedDate                   : chr \"2021-04-15 00:21:45 +0000\"\n##  $ kMDItemLastUsedDate_Ranking           : chr \"2021-04-15 00:00:00 +0000\"\n##  $ kMDItemUseCount                       : chr \"12\"\n##  $ kMDItemFSName                         : chr \"RStudio.app\"\n##  $ kMDItemFSSize                         : chr \"763253198\"\n##  $ kMDItemFSCreationDate                 : chr \"2021-03-25 23:08:34 +0000\"\n##  $ kMDItemFSContentChangeDate            : chr \"2021-03-25 23:08:34 +0000\"\n##  $ kMDItemFSOwnerUserID                  : chr \"501\"\n##  $ kMDItemFSOwnerGroupID                 : chr \"80\"\n##  $ kMDItemFSNodeCount                    : chr \"1\"\n##  $ kMDItemFSInvisible                    : chr \"0\"\n##  $ kMDItemFSTypeCode                     : chr \"0\"\n##  $ kMDItemFSCreatorCode                  : chr \"0\"\n##  $ kMDItemFSFinderFlags                  : chr \"0\"\n##  $ kMDItemFSHasCustomIcon                : chr \"\"\n##  $ kMDItemFSIsExtensionHidden            : chr \"1\"\n##  $ kMDItemFSIsStationery                 : chr \"\"\n##  $ kMDItemFSLabel                        : chr \"0\"\n<\/code><\/pre>\n<p>We&#8217;re still better off (in the long run) checking for and using proper types.<\/p>\n<h3>FIN<\/h3>\n<p>I hope to be able to carve out some more time in the not-too-distant-future for both {swiftr} and the <a href=\"https:\/\/rud.is\/books\/swiftr\/\">in-progress guide on using Swift and R<\/a>, but hopefully this post [re-]piqued interest in this topic for some R and\/or Swift users.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;ve already played with {swiftr} before but were somewhat annoyed at various boilerplate elements [&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-13026","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.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Avoiding The mdls Command Line Round Trip With swiftr::swift_function() - 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\/04\/14\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Avoiding The mdls Command Line Round Trip With swiftr::swift_function() - rud.is\" \/>\n<meta property=\"og:description\" content=\"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&#8217;ve already played with {swiftr} before but were somewhat annoyed at various boilerplate elements [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rud.is\/b\/2021\/04\/14\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\/\" \/>\n<meta property=\"og:site_name\" content=\"rud.is\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-15T00:50:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-04-15T01:32:21+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\\\/04\\\/14\\\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2021\\\/04\\\/14\\\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\\\/\"},\"author\":{\"name\":\"hrbrmstr\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"headline\":\"Avoiding The mdls Command Line Round Trip With swiftr::swift_function()\",\"datePublished\":\"2021-04-15T00:50:51+00:00\",\"dateModified\":\"2021-04-15T01:32:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2021\\\/04\\\/14\\\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\\\/\"},\"wordCount\":435,\"commentCount\":2,\"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\\\/04\\\/14\\\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2021\\\/04\\\/14\\\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\\\/\",\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/2021\\\/04\\\/14\\\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\\\/\",\"name\":\"Avoiding The mdls Command Line Round Trip With swiftr::swift_function() - rud.is\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#website\"},\"datePublished\":\"2021-04-15T00:50:51+00:00\",\"dateModified\":\"2021-04-15T01:32:21+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2021\\\/04\\\/14\\\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2021\\\/04\\\/14\\\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2021\\\/04\\\/14\\\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/rud.is\\\/b\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Avoiding The mdls Command Line Round Trip With swiftr::swift_function()\"}]},{\"@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":"Avoiding The mdls Command Line Round Trip With swiftr::swift_function() - 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\/04\/14\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\/","og_locale":"en_US","og_type":"article","og_title":"Avoiding The mdls Command Line Round Trip With swiftr::swift_function() - rud.is","og_description":"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&#8217;ve already played with {swiftr} before but were somewhat annoyed at various boilerplate elements [&hellip;]","og_url":"https:\/\/rud.is\/b\/2021\/04\/14\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\/","og_site_name":"rud.is","article_published_time":"2021-04-15T00:50:51+00:00","article_modified_time":"2021-04-15T01:32:21+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\/04\/14\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\/#article","isPartOf":{"@id":"https:\/\/rud.is\/b\/2021\/04\/14\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\/"},"author":{"name":"hrbrmstr","@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"headline":"Avoiding The mdls Command Line Round Trip With swiftr::swift_function()","datePublished":"2021-04-15T00:50:51+00:00","dateModified":"2021-04-15T01:32:21+00:00","mainEntityOfPage":{"@id":"https:\/\/rud.is\/b\/2021\/04\/14\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\/"},"wordCount":435,"commentCount":2,"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\/04\/14\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/rud.is\/b\/2021\/04\/14\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\/","url":"https:\/\/rud.is\/b\/2021\/04\/14\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\/","name":"Avoiding The mdls Command Line Round Trip With swiftr::swift_function() - rud.is","isPartOf":{"@id":"https:\/\/rud.is\/b\/#website"},"datePublished":"2021-04-15T00:50:51+00:00","dateModified":"2021-04-15T01:32:21+00:00","breadcrumb":{"@id":"https:\/\/rud.is\/b\/2021\/04\/14\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rud.is\/b\/2021\/04\/14\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/rud.is\/b\/2021\/04\/14\/avoiding-the-mdls-command-line-round-trip-with-swiftrswift_function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/rud.is\/b\/"},{"@type":"ListItem","position":2,"name":"Avoiding The mdls Command Line Round Trip With swiftr::swift_function()"}]},{"@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-3o6","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":12866,"url":"https:\/\/rud.is\/b\/2021\/01\/04\/bringing-r-to-swift-on-macos\/","url_meta":{"origin":13026,"position":0},"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":12878,"url":"https:\/\/rud.is\/b\/2021\/01\/16\/new-swiftr-chapter-up-building-an-r-backed-swiftui-macos-app\/","url_meta":{"origin":13026,"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":12891,"url":"https:\/\/rud.is\/b\/2021\/01\/23\/swiftr-switcheroo-calling-compiled-swift-from-r\/","url_meta":{"origin":13026,"position":2},"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":13026,"position":3},"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":13094,"url":"https:\/\/rud.is\/b\/2021\/05\/22\/a-swiftr-brief-interlude-while-awaiting-cdcfluview-cran-checks\/","url_meta":{"origin":13026,"position":4},"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":"","width":0,"height":0},"classes":[]},{"id":12990,"url":"https:\/\/rud.is\/b\/2021\/03\/13\/retrieve-process-run-time-architecture-on-apple-silicon-macs-on-the-command-line-with-archinfo\/","url_meta":{"origin":13026,"position":5},"title":"Retrieve Process Run-time Architecture on Apple Silicon Macs On The Command Line with `archinfo`","author":"hrbrmstr","date":"2021-03-13","format":false,"excerpt":"Apple M1\/Apple Silicon\/arm64 macOS can run x86_64 programs via Rosetta and most M1 systems currently (~March 2021) very likely run a mix of x86_64 and arm64 processes. Activity Monitor can show the architecture: but command line tools such as ps and top do not due to Apple hiding the details\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":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/13026","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=13026"}],"version-history":[{"count":0,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/13026\/revisions"}],"wp:attachment":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/media?parent=13026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/categories?post=13026"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/tags?post=13026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}