galaaz 0.4.6 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +3575 -118
  3. data/Rakefile +21 -4
  4. data/bin/gknit +152 -6
  5. data/bin/gknit-draft +105 -0
  6. data/bin/gknit-draft.rb +28 -0
  7. data/bin/gknit_Rscript +127 -0
  8. data/bin/grun +27 -1
  9. data/bin/gstudio +47 -4
  10. data/bin/{gstudio.rb → gstudio_irb.rb} +0 -0
  11. data/bin/gstudio_pry.rb +7 -0
  12. data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +3 -12
  13. data/blogs/galaaz_ggplot/galaaz_ggplot.html +77 -222
  14. data/blogs/galaaz_ggplot/galaaz_ggplot.md +4 -31
  15. data/blogs/galaaz_ggplot/galaaz_ggplot.pdf +0 -0
  16. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/midwest_rb.png +0 -0
  17. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/scatter_plot_rb.png +0 -0
  18. data/blogs/galaaz_ggplot/midwest.Rmd +1 -9
  19. data/blogs/gknit/gknit.Rmd +232 -123
  20. data/blogs/{dev/dev.html → gknit/gknit.html} +1897 -33
  21. data/blogs/gknit/gknit.pdf +0 -0
  22. data/blogs/gknit/lst.rds +0 -0
  23. data/blogs/gknit/stats.bib +27 -0
  24. data/blogs/manual/lst.rds +0 -0
  25. data/blogs/manual/manual.Rmd +1893 -47
  26. data/blogs/manual/manual.html +3153 -347
  27. data/blogs/manual/manual.md +3575 -118
  28. data/blogs/manual/manual.pdf +0 -0
  29. data/blogs/manual/manual.tex +4026 -0
  30. data/blogs/manual/manual_files/figure-html/bubble-1.png +0 -0
  31. data/blogs/manual/manual_files/figure-html/diverging_bar.png +0 -0
  32. data/blogs/manual/manual_files/figure-latex/bubble-1.png +0 -0
  33. data/blogs/manual/manual_files/figure-latex/diverging_bar.pdf +0 -0
  34. data/blogs/{dev → manual}/model.rb +0 -0
  35. data/blogs/nse_dplyr/nse_dplyr.Rmd +849 -0
  36. data/blogs/nse_dplyr/nse_dplyr.html +878 -0
  37. data/blogs/nse_dplyr/nse_dplyr.md +1198 -0
  38. data/blogs/nse_dplyr/nse_dplyr.pdf +0 -0
  39. data/blogs/oh_my/oh_my.html +274 -386
  40. data/blogs/oh_my/oh_my.md +208 -205
  41. data/blogs/ruby_plot/ruby_plot.Rmd +64 -84
  42. data/blogs/ruby_plot/ruby_plot.html +235 -208
  43. data/blogs/ruby_plot/ruby_plot.md +239 -34
  44. data/blogs/ruby_plot/ruby_plot.pdf +0 -0
  45. data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.png +0 -0
  46. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_delivery.png +0 -0
  47. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_dose.png +0 -0
  48. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color.png +0 -0
  49. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color2.png +0 -0
  50. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_decorations.png +0 -0
  51. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.png +0 -0
  52. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_points.png +0 -0
  53. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_box_plot.png +0 -0
  54. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_violin_plot.png +0 -0
  55. data/blogs/ruby_plot/ruby_plot_files/figure-html/violin_with_jitter.png +0 -0
  56. data/examples/Bibliography/master.bib +50 -0
  57. data/examples/Bibliography/stats.bib +72 -0
  58. data/examples/islr/ch2.spec.rb +1 -1
  59. data/examples/islr/ch3_boston.rb +4 -4
  60. data/examples/islr/x_y_rnorm.jpg +0 -0
  61. data/examples/latex_templates/Test-acm_article/Makefile +16 -0
  62. data/examples/latex_templates/Test-acm_article/Test-acm_article.Rmd +65 -0
  63. data/examples/latex_templates/Test-acm_article/acm_proc_article-sp.cls +1670 -0
  64. data/examples/latex_templates/Test-acm_article/sensys-abstract.cls +703 -0
  65. data/examples/latex_templates/Test-acm_article/sigproc.bib +59 -0
  66. data/examples/latex_templates/Test-acs_article/Test-acs_article.Rmd +260 -0
  67. data/examples/latex_templates/Test-acs_article/Test-acs_article.pdf +0 -0
  68. data/examples/latex_templates/Test-acs_article/acs-Test-acs_article.bib +11 -0
  69. data/examples/latex_templates/Test-acs_article/acs-my_output.bib +11 -0
  70. data/examples/latex_templates/Test-acs_article/acstest.bib +17 -0
  71. data/examples/latex_templates/Test-aea_article/AEA.cls +1414 -0
  72. data/examples/latex_templates/Test-aea_article/BibFile.bib +0 -0
  73. data/examples/latex_templates/Test-aea_article/Test-aea_article.Rmd +108 -0
  74. data/examples/latex_templates/Test-aea_article/Test-aea_article.pdf +0 -0
  75. data/examples/latex_templates/Test-aea_article/aea.bst +1269 -0
  76. data/examples/latex_templates/Test-aea_article/multicol.sty +853 -0
  77. data/examples/latex_templates/Test-aea_article/references.bib +0 -0
  78. data/examples/latex_templates/Test-aea_article/setspace.sty +546 -0
  79. data/examples/latex_templates/Test-amq_article/Test-amq_article.Rmd +256 -0
  80. data/examples/latex_templates/Test-amq_article/Test-amq_article.pdf +0 -0
  81. data/examples/latex_templates/Test-amq_article/Test-amq_article.pdfsync +3397 -0
  82. data/examples/latex_templates/Test-amq_article/pics/Figure2.pdf +0 -0
  83. data/examples/latex_templates/Test-ams_article/Test-ams_article.Rmd +215 -0
  84. data/examples/latex_templates/Test-ams_article/amstest.bib +436 -0
  85. data/examples/latex_templates/Test-asa_article/Test-asa_article.Rmd +153 -0
  86. data/examples/latex_templates/Test-asa_article/Test-asa_article.pdf +0 -0
  87. data/examples/latex_templates/Test-asa_article/agsm.bst +1353 -0
  88. data/examples/latex_templates/Test-asa_article/bibliography.bib +233 -0
  89. data/examples/latex_templates/Test-ieee_article/IEEEtran.bst +2409 -0
  90. data/examples/latex_templates/Test-ieee_article/IEEEtran.cls +6346 -0
  91. data/examples/latex_templates/Test-ieee_article/Test-ieee_article.Rmd +175 -0
  92. data/examples/latex_templates/Test-ieee_article/Test-ieee_article.pdf +0 -0
  93. data/examples/latex_templates/Test-ieee_article/mybibfile.bib +20 -0
  94. data/examples/latex_templates/Test-rjournal_article/RJournal.sty +335 -0
  95. data/examples/latex_templates/Test-rjournal_article/RJreferences.bib +18 -0
  96. data/examples/latex_templates/Test-rjournal_article/RJwrapper.pdf +0 -0
  97. data/examples/latex_templates/Test-rjournal_article/Test-rjournal_article.Rmd +52 -0
  98. data/examples/latex_templates/Test-springer_article/Test-springer_article.Rmd +65 -0
  99. data/examples/latex_templates/Test-springer_article/Test-springer_article.pdf +0 -0
  100. data/examples/latex_templates/Test-springer_article/bibliography.bib +26 -0
  101. data/examples/latex_templates/Test-springer_article/spbasic.bst +1658 -0
  102. data/examples/latex_templates/Test-springer_article/spmpsci.bst +1512 -0
  103. data/examples/latex_templates/Test-springer_article/spphys.bst +1443 -0
  104. data/examples/latex_templates/Test-springer_article/svglov3.clo +113 -0
  105. data/examples/latex_templates/Test-springer_article/svjour3.cls +1431 -0
  106. data/examples/misc/moneyball.rb +1 -1
  107. data/examples/misc/subsetting.rb +37 -37
  108. data/examples/rmarkdown/svm-rmarkdown-anon-ms-example/svm-rmarkdown-anon-ms-example.Rmd +73 -0
  109. data/examples/rmarkdown/svm-rmarkdown-anon-ms-example/svm-rmarkdown-anon-ms-example.pdf +0 -0
  110. data/examples/rmarkdown/svm-rmarkdown-article-example/svm-rmarkdown-article-example.Rmd +382 -0
  111. data/examples/rmarkdown/svm-rmarkdown-article-example/svm-rmarkdown-article-example.pdf +0 -0
  112. data/examples/rmarkdown/svm-rmarkdown-beamer-example/svm-rmarkdown-beamer-example.Rmd +164 -0
  113. data/examples/rmarkdown/svm-rmarkdown-beamer-example/svm-rmarkdown-beamer-example.pdf +0 -0
  114. data/examples/rmarkdown/svm-rmarkdown-cv/svm-rmarkdown-cv.Rmd +92 -0
  115. data/examples/rmarkdown/svm-rmarkdown-cv/svm-rmarkdown-cv.pdf +0 -0
  116. data/examples/rmarkdown/svm-rmarkdown-syllabus-example/attend-grade-relationships.csv +482 -0
  117. data/examples/rmarkdown/svm-rmarkdown-syllabus-example/svm-rmarkdown-syllabus-example.Rmd +280 -0
  118. data/examples/rmarkdown/svm-rmarkdown-syllabus-example/svm-rmarkdown-syllabus-example.pdf +0 -0
  119. data/examples/rmarkdown/svm-xaringan-example/svm-xaringan-example.Rmd +386 -0
  120. data/lib/R_interface/r.rb +2 -2
  121. data/lib/R_interface/r_libs.R +6 -1
  122. data/lib/R_interface/r_methods.rb +12 -2
  123. data/lib/R_interface/rdata_frame.rb +8 -17
  124. data/lib/R_interface/rindexed_object.rb +1 -2
  125. data/lib/R_interface/rlist.rb +1 -0
  126. data/lib/R_interface/robject.rb +20 -23
  127. data/lib/R_interface/rpkg.rb +15 -6
  128. data/lib/R_interface/rsupport.rb +13 -19
  129. data/lib/R_interface/ruby_extensions.rb +14 -18
  130. data/lib/R_interface/rvector.rb +0 -12
  131. data/lib/gknit.rb +2 -0
  132. data/lib/gknit/draft.rb +105 -0
  133. data/lib/gknit/knitr_engine.rb +6 -37
  134. data/lib/util/exec_ruby.rb +22 -84
  135. data/lib/util/inline_file.rb +7 -3
  136. data/specs/figures/bg.jpeg +0 -0
  137. data/specs/figures/bg.png +0 -0
  138. data/specs/figures/bg.svg +2 -2
  139. data/specs/figures/dose_len.png +0 -0
  140. data/specs/figures/no_args.jpeg +0 -0
  141. data/specs/figures/no_args.png +0 -0
  142. data/specs/figures/no_args.svg +2 -2
  143. data/specs/figures/width_height.jpeg +0 -0
  144. data/specs/figures/width_height.png +0 -0
  145. data/specs/figures/width_height_units1.jpeg +0 -0
  146. data/specs/figures/width_height_units1.png +0 -0
  147. data/specs/figures/width_height_units2.jpeg +0 -0
  148. data/specs/figures/width_height_units2.png +0 -0
  149. data/specs/r_dataframe.spec.rb +184 -11
  150. data/specs/r_list.spec.rb +4 -4
  151. data/specs/r_list_apply.spec.rb +11 -10
  152. data/specs/ruby_expression.spec.rb +3 -11
  153. data/specs/tmp.rb +106 -34
  154. data/version.rb +1 -1
  155. metadata +96 -33
  156. data/bin/gknit_old_r +0 -236
  157. data/blogs/dev/dev.Rmd +0 -77
  158. data/blogs/dev/dev.md +0 -87
  159. data/blogs/dev/dev_files/figure-html/bubble-1.png +0 -0
  160. data/blogs/dev/dev_files/figure-html/diverging_bar. +0 -0
  161. data/blogs/dev/dev_files/figure-html/diverging_bar.png +0 -0
  162. data/blogs/dplyr/dplyr.rb +0 -63
  163. data/blogs/galaaz_ggplot/galaaz_ggplot.aux +0 -43
  164. data/blogs/galaaz_ggplot/galaaz_ggplot.log +0 -640
  165. data/blogs/galaaz_ggplot/galaaz_ggplot.out +0 -10
  166. data/blogs/galaaz_ggplot/galaaz_ggplot.tex +0 -481
  167. data/blogs/galaaz_ggplot/midwest.png +0 -0
  168. data/blogs/galaaz_ggplot/scatter_plot.png +0 -0
  169. data/blogs/ruby_plot/ruby_plot.Rmd_external_figs +0 -662
  170. data/blogs/ruby_plot/ruby_plot.tex +0 -1077
  171. data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.svg +0 -57
  172. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_delivery.svg +0 -106
  173. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_dose.svg +0 -110
  174. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color.svg +0 -174
  175. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color2.svg +0 -236
  176. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.svg +0 -296
  177. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_points.svg +0 -236
  178. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_box_plot.svg +0 -218
  179. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_violin_plot.svg +0 -128
  180. data/blogs/ruby_plot/ruby_plot_files/figure-html/violin_with_jitter.svg +0 -150
  181. data/examples/paper/paper.rb +0 -36
@@ -1,236 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # coding: utf-8
3
-
4
- dir = Dir.pwd
5
- puts "Knitting #{dir}/#{ARGV[0]}"
6
-
7
- code = <<EOF
8
- eval.polyglot("ruby", "$LOAD_PATH.unshift %q(/home/rbotafogo/desenv/galaaz/lib)")
9
- eval.polyglot("ruby", "require %q(galaaz)")
10
- eval.polyglot("ruby", "R.install_and_loads %q(knitr)")
11
- eval.polyglot("ruby", "R.install_and_loads %q(rmarkdown)")
12
-
13
- # graphics devices in base R, plus those in Cairo, cairoDevice, tikzDevice
14
- auto_exts = c(
15
- bmp = "bmp", postscript = "eps", pdf = "pdf", png = "png", svg = "svg",
16
- jpeg = "jpeg", pictex = "tex", tiff = "tiff", win.metafile = "wmf",
17
- cairo_pdf = "pdf", cairo_ps = "eps",
18
-
19
- quartz_pdf = "pdf", quartz_png = "png", quartz_jpeg = "jpeg",
20
- quartz_tiff = "tiff", quartz_gif = "gif", quartz_psd = "psd",
21
- quartz_bmp = "bmp",
22
-
23
- CairoJPEG = "jpeg", CairoPNG = "png", CairoPS = "eps", CairoPDF = "pdf",
24
- CairoSVG = "svg", CairoTIFF = "tiff",
25
-
26
- Cairo_pdf = "pdf", Cairo_png = "png", Cairo_ps = "eps", Cairo_svg = "svg",
27
-
28
- svglite = "svg",
29
-
30
- tikz = "tex"
31
- )
32
-
33
- is_plot_output = function(x) {
34
- evaluate::is.recordedplot(x) || inherits(x, "knit_image_paths")
35
- }
36
-
37
- # find recorded plots in the output of evaluate()
38
- find_recordedplot = function(x) {
39
- vapply(x, is_plot_output, logical(1))
40
- }
41
-
42
- dev2ext = function(x) {
43
- res = auto_exts[x]
44
- if (any(idx <- is.na(res))) {
45
- for (i in x[idx]) check_dev(i)
46
- stop2(
47
- "cannot find appropriate filename extensions for device ", x[idx], "; ",
48
- "please use chunk option 'fig.ext' (https://yihui.name/knitr/options)"
49
- )
50
- }
51
- unname(res)
52
- }
53
-
54
- # filter the dev.args option
55
- get_dargs = function(dargs, dev) {
56
- if (length(dargs) == 0) return()
57
- if (is.list(dargs) && all(sapply(dargs, is.list))) {
58
- # dev.args is list(dev1 = list(arg1 = val1, ...), dev2 = list(arg2, ...))
59
- dargs = dargs[[dev]]
60
- }
61
- dargs
62
- }
63
-
64
- # open a device for a chunk; depending on the option global.device, may or may
65
- # not need to close the device on exit
66
- chunk_device = function(
67
- width, height, record = TRUE, dev, dev.args, dpi, options, tmp = tempfile()
68
- ) {
69
- dev_new = function() {
70
- # actually I should adjust the recording device according to dev, but here I
71
- # have only considered the png and tikz devices (because the measurement
72
- # results can be very different especially with the latter, see #1066), and
73
- # also the cairo_pdf device (#1235)
74
- if (identical(dev, "png")) {
75
- do.call(grDevices::png, c(list(
76
- filename = tmp, width = width, height = height, units = "in", res = dpi
77
- ), get_dargs(dev.args, "png")))
78
- } else if (identical(dev, "tikz")) {
79
- dargs = c(list(
80
- file = tmp, width = width, height = height
81
- ), get_dargs(dev.args, "tikz"))
82
- dargs$sanitize = options$sanitize; dargs$standAlone = options$external
83
- if (is.null(dargs$verbose)) dargs$verbose = FALSE
84
- do.call(tikz_dev, dargs)
85
- } else if (identical(dev, "cairo_pdf")) {
86
- do.call(grDevices::cairo_pdf, c(list(
87
- filename = tmp, width = width, height = height
88
- ), get_dargs(dev.args, "cairo_pdf")))
89
- } else if (identical(getOption("device"), "pdf_null")) {
90
- if (!is.null(dev.args)) {
91
- dev.args = get_dargs(dev.args, "pdf")
92
- dev.args = dev.args[intersect(names(dev.args), c("pointsize", "bg"))]
93
- }
94
- do.call(pdf_null, c(list(width = width, height = height), dev.args))
95
- } else dev.new(width = width, height = height)
96
- }
97
- if (!opts_knit$get("global.device")) {
98
- dev_new()
99
- dev.control(displaylist = if (record) "enable" else "inhibit") # enable recording
100
- # if returns TRUE, we need to close this device after code is evaluated
101
- return(TRUE)
102
- } else if (is.null(dev.list())) {
103
- # want to use a global device but not open yet
104
- dev_new()
105
- dev.control("enable")
106
- }
107
- FALSE
108
- }
109
-
110
- showtext = function(show) if (isTRUE(show)) showtext::showtext_begin()
111
-
112
- #########################################################################################
113
-
114
- # define the ruby engine for processing Ruby chunks in
115
- # rmarkdown
116
- eng_ruby = function(options) {
117
- block_code = paste(options$code, collapse = "\\n");
118
- code = paste0("GalaazUtil.exec_ruby_tor(",
119
- shQuote(block_code),
120
- ")
121
- ");
122
-
123
- keep = options$fig.keep
124
- keep.idx = NULL
125
- if (is.numeric(keep)) {
126
- keep.idx = keep
127
- keep = "index"
128
- }
129
-
130
- tmp.fig = tempfile(); on.exit(unlink(tmp.fig), add = TRUE)
131
-
132
- # open a device to record plots
133
- if (chunk_device(options$fig.width[1L], options$fig.height[1L], keep != "none",
134
- options$dev, options$dev.args, options$dpi, options, tmp.fig)) {
135
- # preserve par() settings from the last code chunk
136
- if (keep.pars <- opts_knit$get("global.par"))
137
- par2(opts_knit$get("global.pars"))
138
- showtext(options$fig.showtext) # showtext support
139
- dv = dev.cur()
140
- on.exit({
141
- if (keep.pars) opts_knit$set(global.pars = par(no.readonly = TRUE))
142
- dev.off(dv)
143
- }, add = TRUE)
144
- }
145
-
146
- # guess plot file type if it is NULL
147
- # if (keep != "none" && is.null(options$fig.ext))
148
- # options$fig.ext = dev2ext(options$dev)
149
-
150
- res = eval.polyglot("ruby", code);
151
-
152
- # rearrange locations of figures
153
- # figs = find_recordedplot(res)
154
- # if (length(figs) && any(figs)) {
155
- # if (keep == 'none') {
156
- # res = res[!figs] # remove all
157
- # } else {
158
- # if (options$fig.show == 'hold') res = c(res[!figs], res[figs]) # move to the end
159
- # figs = find_recordedplot(res)
160
- # if (length(figs) && sum(figs) > 1) {
161
- # if (keep %in% c('first', 'last')) {
162
- # res = res[-(if (keep == 'last') head else tail)(which(figs), -1L)]
163
- # } else {
164
- # # keep only selected
165
- # if (keep == 'index') res = res[which(figs)[keep.idx]]
166
- # # merge low-level plotting changes
167
- # if (keep == 'high') res = merge_low_plot(res, figs)
168
- # }
169
- # }
170
- # }
171
- #}
172
-
173
- engine_output(options, out = res)
174
-
175
- # out_list = list(source = block_code, text = res, message = "message from Galaaz",
176
- # warning = "Warning from Galaaz", error = "Error from Galaaz",
177
- # value = "Value from Galaaz")
178
- # engine_output(options, out = out_list)
179
- # engine_output(options, block_code, res)
180
- }
181
-
182
- knit_engines$set(ruby = eng_ruby)
183
-
184
- #########################################################################################
185
-
186
- # define the rb engine for inline Ruby code
187
- eng_rb = function(options) {
188
- code = paste0("GalaazUtil.exec_ruby(",
189
- shQuote(options$label),
190
- ")
191
- ");
192
- out = eval.polyglot("ruby", code)
193
- return(out)
194
- }
195
-
196
- knit_engines$set(rb = eng_rb)
197
-
198
- #########################################################################################
199
-
200
- # define the include engine for including Ruby files
201
- # in place
202
-
203
- eng_include = function(options) {
204
- if (is.null(options$relative) | isTRUE(options$relative)) {
205
- req = "require_relative "
206
- } else {
207
- req = "require "
208
- }
209
-
210
- # read the file and store it to output in the code block
211
- code = paste0("GalaazUtil.inline_file(",
212
- shQuote(options$label),
213
- ", ",
214
- shQuote(req),
215
- ")
216
- ");
217
- include = eval.polyglot("ruby", code);
218
-
219
- # require the file
220
- require = paste0(req, shQuote(options$label));
221
- code = paste0("GalaazUtil.exec_ruby(",
222
- shQuote(require),
223
- ")
224
- ");
225
-
226
- out = eval.polyglot("ruby", code);
227
- engine_output(options, include, out)
228
- }
229
-
230
- knit_engines$set(include = eng_include)
231
-
232
-
233
- rmarkdown::render("#{dir}/#{ARGV[0]}")
234
- EOF
235
-
236
- exec "Rscript --jvm --polyglot -e '#{code}'"
@@ -1,77 +0,0 @@
1
- ---
2
- title: "gKnit - Ruby and R Knitting with Galaaz in GraalVM"
3
- author: "Rodrigo Botafogo"
4
- tags: [Galaaz, Ruby, R, TruffleRuby, FastR, GraalVM, knitr]
5
- date: "19 October 2018"
6
- output:
7
- html_document:
8
- self_contained: true
9
- keep_md: true
10
- pdf_document:
11
- includes:
12
- in_header: ["../../sty/galaaz.sty"]
13
- number_sections: yes
14
- ---
15
-
16
- ```{r setup, echo=FALSE}
17
-
18
- ```
19
-
20
- # Introduction
21
-
22
-
23
- ```{r bubble}
24
- # load package and data
25
- library(ggplot2)
26
- data(mpg, package="ggplot2")
27
- # mpg <- read.csv("http://goo.gl/uEeRGu")
28
-
29
- mpg_select <- mpg[mpg$manufacturer %in% c("audi", "ford", "honda", "hyundai"), ]
30
-
31
- # Scatterplot
32
- theme_set(theme_bw()) # pre-set the bw theme.
33
- g <- ggplot(mpg_select, aes(displ, cty)) +
34
- labs(subtitle="mpg: Displacement vs City Mileage",
35
- title="Bubble chart")
36
-
37
- g + geom_jitter(aes(col=manufacturer, size=hwy)) +
38
- geom_smooth(aes(col=manufacturer), method="lm", se=F)
39
- ```
40
-
41
- ### Plotting
42
-
43
- ```{ruby diverging_bar}
44
- require 'ggplot'
45
-
46
- R.theme_set R.theme_bw
47
-
48
- # Data Prep
49
- mtcars = ~:mtcars
50
- mtcars.car_name = R.rownames(:mtcars)
51
- # compute normalized mpg
52
- mtcars.mpg_z = ((mtcars.mpg - mtcars.mpg.mean)/mtcars.mpg.sd).round 2
53
- mtcars.mpg_type = mtcars.mpg_z < 0 ? "below" : "above"
54
- mtcars = mtcars[mtcars.mpg_z.order, :all]
55
- # convert to factor to retain sorted order in plot
56
- mtcars.car_name = mtcars.car_name.factor levels: mtcars.car_name
57
-
58
- # Diverging Barcharts
59
- gg = mtcars.ggplot(E.aes(x: :car_name, y: :mpg_z, label: :mpg_z)) +
60
- R.geom_bar(E.aes(fill: :mpg_type), stat: 'identity', width: 0.5) +
61
- R.scale_fill_manual(name: "Mileage",
62
- labels: R.c("Above Average", "Below Average"),
63
- values: R.c("above": "#00ba38", "below": "#f8766d")) +
64
- R.labs(subtitle: "Normalised mileage from 'mtcars'",
65
- title: "Diverging Bars") +
66
- R.coord_flip()
67
-
68
- print gg
69
- ```
70
-
71
- ![Diverging Barcharts](dev_files/figure-html/diverging_bar.png){width=70%}
72
-
73
-
74
- ```{ruby vec}
75
- @vec = R.c(1, 2, 3)
76
- puts @vec
77
- ```
@@ -1,87 +0,0 @@
1
- ---
2
- title: "gKnit - Ruby and R Knitting with Galaaz in GraalVM"
3
- author: "Rodrigo Botafogo"
4
- tags: [Galaaz, Ruby, R, TruffleRuby, FastR, GraalVM, knitr]
5
- date: "19 October 2018"
6
- output:
7
- html_document:
8
- self_contained: true
9
- keep_md: true
10
- pdf_document:
11
- includes:
12
- in_header: ["../../sty/galaaz.sty"]
13
- number_sections: yes
14
- ---
15
-
16
-
17
-
18
- # Introduction
19
-
20
-
21
-
22
- ```r
23
- # load package and data
24
- library(ggplot2)
25
- data(mpg, package="ggplot2")
26
- # mpg <- read.csv("http://goo.gl/uEeRGu")
27
-
28
- mpg_select <- mpg[mpg$manufacturer %in% c("audi", "ford", "honda", "hyundai"), ]
29
-
30
- # Scatterplot
31
- theme_set(theme_bw()) # pre-set the bw theme.
32
- g <- ggplot(mpg_select, aes(displ, cty)) +
33
- labs(subtitle="mpg: Displacement vs City Mileage",
34
- title="Bubble chart")
35
-
36
- g + geom_jitter(aes(col=manufacturer, size=hwy)) +
37
- geom_smooth(aes(col=manufacturer), method="lm", se=F)
38
- ```
39
-
40
- ![](/home/rbotafogo/desenv/galaaz/blogs/dev/dev_files/figure-html/bubble-1.png)<!-- -->
41
-
42
- ### Plotting
43
-
44
-
45
- ```ruby
46
- require 'ggplot'
47
-
48
- R.theme_set R.theme_bw
49
-
50
- # Data Prep
51
- mtcars = ~:mtcars
52
- mtcars.car_name = R.rownames(:mtcars)
53
- # compute normalized mpg
54
- mtcars.mpg_z = ((mtcars.mpg - mtcars.mpg.mean)/mtcars.mpg.sd).round 2
55
- mtcars.mpg_type = mtcars.mpg_z < 0 ? "below" : "above"
56
- mtcars = mtcars[mtcars.mpg_z.order, :all]
57
- # convert to factor to retain sorted order in plot
58
- mtcars.car_name = mtcars.car_name.factor levels: mtcars.car_name
59
-
60
- # Diverging Barcharts
61
- gg = mtcars.ggplot(E.aes(x: :car_name, y: :mpg_z, label: :mpg_z)) +
62
- R.geom_bar(E.aes(fill: :mpg_type), stat: 'identity', width: 0.5) +
63
- R.scale_fill_manual(name: "Mileage",
64
- labels: R.c("Above Average", "Below Average"),
65
- values: R.c("above": "#00ba38", "below": "#f8766d")) +
66
- R.labs(subtitle: "Normalised mileage from 'mtcars'",
67
- title: "Diverging Bars") +
68
- R.coord_flip()
69
-
70
- print gg
71
- ```
72
-
73
- ```
74
- ## This is the fake output
75
- ```
76
-
77
- ![Diverging Barcharts](dev_files/figure-html/diverging_bar.png){width=70%}
78
-
79
-
80
- ```ruby
81
- @vec = R.c(1, 2, 3)
82
- puts @vec
83
- ```
84
-
85
- ```
86
- ## This is the fake output
87
- ```
@@ -1,63 +0,0 @@
1
- R.library('dplyr')
2
- R.library('nycflights13')
3
-
4
- puts R.filter(:flights, (:month.eq 1), (:day.eq 1)) # exec time: 0.15 sec
5
-
6
- flights = ~:flights
7
-
8
- puts flights
9
-
10
- # In this call, 'flights' will be inlined in the expression and
11
- # passed to method 'filter'. If 'filter' wants to print it's
12
- # first argument, it will print the dataframe.
13
- puts flights.filter((:month.eq 1), (:day.eq 1)) # exec time: 0.146 sec
14
-
15
- # In this call, the symbol 'flights' is the first argument to method
16
- # filter. If 'filter' wants to print it's arguments, it will print
17
- # 'flights'.
18
- puts :flights.filter((:month.eq 1), (:day.eq 1))
19
-
20
- puts flights.filter((:month.eq 12), (:day.eq 25))
21
- puts flights.filter(:month._ :in, R.c(11, 12))
22
- puts flights.filter(!((:arr_delay > 120) | (:dep_delay > 120)))
23
- puts flights.arrange(:year, :month, :day)
24
- puts flights.arrange(E.desc(:arr_delay))
25
- puts flights.select(:year, :month, :day)
26
- puts flights.select(R::S.columns(:year, :day))
27
- puts flights.select(R::S.columns(:year, :day, remove: true))
28
- puts flights.rename(tail_num: :tailnum)
29
- puts flights.select(:time_hour, :air_time, E.everything)
30
-
31
- #=begin
32
- flights_sml =
33
- flights.
34
- select(R::S.columns(:year, :day),
35
- E.ends_with("delay"),
36
- :distance,
37
- :air_time)
38
-
39
- puts flights_sml
40
-
41
- puts flights_sml.mutate(gain: (:arr_delay - :dep_delay),
42
- speed: (:distance / :air_time * 60))
43
-
44
- puts flights_sml.mutate(gain: :arr_delay - :dep_delay,
45
- hours: (:air_time / 60),
46
- gain_per_hour: (:gain / :hours))
47
-
48
- #=end
49
-
50
- #=begin
51
- expr = E.transmute(:flights, :dep_time,
52
- hour: (:dep_time.int_div 100.0),
53
- minute: :dep_time % 100.0)
54
- puts expr
55
- puts expr.ast
56
- puts expr.eval
57
-
58
-
59
- lst = R.list(x: 10, y: 20)
60
- e = E.eval(:sum, :x, :y, lst)
61
- e.eval
62
-
63
- #=end