You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.0 KiB

3 months ago
  1. ---
  2. output: rmarkdown::github_document
  3. editor_options:
  4. chunk_output_type: console
  5. ---
  6. ```{r pkg-knitr-opts, include=FALSE}
  7. hrbrpkghelpr::global_opts()
  8. ```
  9. ```{r badges, results='asis', echo=FALSE, cache=FALSE}
  10. hrbrpkghelpr::stinking_badges()
  11. ```
  12. ```{r description, results='asis', echo=FALSE, cache=FALSE}
  13. hrbrpkghelpr::yank_title_and_description()
  14. ```
  15. ## What's Inside The Tin
  16. The following functions are implemented:
  17. ```{r ingredients, results='asis', echo=FALSE, cache=FALSE}
  18. hrbrpkghelpr::describe_ingredients()
  19. ```
  20. ## Installation
  21. ```{r install-ex, results='asis', echo=FALSE, cache=FALSE}
  22. hrbrpkghelpr::install_block()
  23. ```
  24. ## Usage
  25. ```{r lib-ex}
  26. library(swiftr)
  27. # current version
  28. packageVersion("swiftr")
  29. ```
  30. ```{r ex01}
  31. swift_function(
  32. code = '
  33. func ignored() {
  34. print("""
  35. this will be ignored by swift_function() but you could use private
  36. functions as helpers for the main public Swift function which will be
  37. made available to R.
  38. """)
  39. }
  40. @_cdecl ("read_plist")
  41. public func read_plist(path: SEXP) -> SEXP {
  42. var out: SEXP = R_NilValue
  43. do {
  44. // read in the raw plist
  45. let plistRaw = try Data(contentsOf: URL(fileURLWithPath: String(cString: R_CHAR(STRING_ELT(path, 0)))))
  46. // convert it to a PropertyList
  47. let plist = try PropertyListSerialization.propertyList(from: plistRaw, options: [], format: nil) as! [String:Any]
  48. // serialize it to JSON
  49. let jsonData = try JSONSerialization.data(withJSONObject: plist , options: .prettyPrinted)
  50. // setup the JSON string return
  51. String(data: jsonData, encoding: .utf8)?.withCString {
  52. cstr in out = Rf_mkString(cstr)
  53. }
  54. } catch {
  55. debugPrint("\\(error)")
  56. }
  57. return(out)
  58. }
  59. ')
  60. read_plist("/Applications/RStudio.app/Contents/Info.plist") %>%
  61. jsonlite::fromJSON() %>%
  62. str(1)
  63. ```
  64. ## swiftr Metrics
  65. ```{r cloc, echo=FALSE}
  66. cloc::cloc_pkg_md()
  67. ```
  68. ## Code of Conduct
  69. Please note that this project is released with a Contributor Code of Conduct.
  70. By participating in this project you agree to abide by its terms.