galaaz 0.4.6 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +3575 -118
- data/Rakefile +21 -4
- data/bin/gknit +152 -6
- data/bin/gknit-draft +105 -0
- data/bin/gknit-draft.rb +28 -0
- data/bin/gknit_Rscript +127 -0
- data/bin/grun +27 -1
- data/bin/gstudio +47 -4
- data/bin/{gstudio.rb → gstudio_irb.rb} +0 -0
- data/bin/gstudio_pry.rb +7 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +3 -12
- data/blogs/galaaz_ggplot/galaaz_ggplot.html +77 -222
- data/blogs/galaaz_ggplot/galaaz_ggplot.md +4 -31
- data/blogs/galaaz_ggplot/galaaz_ggplot.pdf +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/midwest_rb.png +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/scatter_plot_rb.png +0 -0
- data/blogs/galaaz_ggplot/midwest.Rmd +1 -9
- data/blogs/gknit/gknit.Rmd +232 -123
- data/blogs/{dev/dev.html → gknit/gknit.html} +1897 -33
- data/blogs/gknit/gknit.pdf +0 -0
- data/blogs/gknit/lst.rds +0 -0
- data/blogs/gknit/stats.bib +27 -0
- data/blogs/manual/lst.rds +0 -0
- data/blogs/manual/manual.Rmd +1893 -47
- data/blogs/manual/manual.html +3153 -347
- data/blogs/manual/manual.md +3575 -118
- data/blogs/manual/manual.pdf +0 -0
- data/blogs/manual/manual.tex +4026 -0
- data/blogs/manual/manual_files/figure-html/bubble-1.png +0 -0
- data/blogs/manual/manual_files/figure-html/diverging_bar.png +0 -0
- data/blogs/manual/manual_files/figure-latex/bubble-1.png +0 -0
- data/blogs/manual/manual_files/figure-latex/diverging_bar.pdf +0 -0
- data/blogs/{dev → manual}/model.rb +0 -0
- data/blogs/nse_dplyr/nse_dplyr.Rmd +849 -0
- data/blogs/nse_dplyr/nse_dplyr.html +878 -0
- data/blogs/nse_dplyr/nse_dplyr.md +1198 -0
- data/blogs/nse_dplyr/nse_dplyr.pdf +0 -0
- data/blogs/oh_my/oh_my.html +274 -386
- data/blogs/oh_my/oh_my.md +208 -205
- data/blogs/ruby_plot/ruby_plot.Rmd +64 -84
- data/blogs/ruby_plot/ruby_plot.html +235 -208
- data/blogs/ruby_plot/ruby_plot.md +239 -34
- data/blogs/ruby_plot/ruby_plot.pdf +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_delivery.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_dose.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color2.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_decorations.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_points.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/final_box_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/final_violin_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/violin_with_jitter.png +0 -0
- data/examples/Bibliography/master.bib +50 -0
- data/examples/Bibliography/stats.bib +72 -0
- data/examples/islr/ch2.spec.rb +1 -1
- data/examples/islr/ch3_boston.rb +4 -4
- data/examples/islr/x_y_rnorm.jpg +0 -0
- data/examples/latex_templates/Test-acm_article/Makefile +16 -0
- data/examples/latex_templates/Test-acm_article/Test-acm_article.Rmd +65 -0
- data/examples/latex_templates/Test-acm_article/acm_proc_article-sp.cls +1670 -0
- data/examples/latex_templates/Test-acm_article/sensys-abstract.cls +703 -0
- data/examples/latex_templates/Test-acm_article/sigproc.bib +59 -0
- data/examples/latex_templates/Test-acs_article/Test-acs_article.Rmd +260 -0
- data/examples/latex_templates/Test-acs_article/Test-acs_article.pdf +0 -0
- data/examples/latex_templates/Test-acs_article/acs-Test-acs_article.bib +11 -0
- data/examples/latex_templates/Test-acs_article/acs-my_output.bib +11 -0
- data/examples/latex_templates/Test-acs_article/acstest.bib +17 -0
- data/examples/latex_templates/Test-aea_article/AEA.cls +1414 -0
- data/examples/latex_templates/Test-aea_article/BibFile.bib +0 -0
- data/examples/latex_templates/Test-aea_article/Test-aea_article.Rmd +108 -0
- data/examples/latex_templates/Test-aea_article/Test-aea_article.pdf +0 -0
- data/examples/latex_templates/Test-aea_article/aea.bst +1269 -0
- data/examples/latex_templates/Test-aea_article/multicol.sty +853 -0
- data/examples/latex_templates/Test-aea_article/references.bib +0 -0
- data/examples/latex_templates/Test-aea_article/setspace.sty +546 -0
- data/examples/latex_templates/Test-amq_article/Test-amq_article.Rmd +256 -0
- data/examples/latex_templates/Test-amq_article/Test-amq_article.pdf +0 -0
- data/examples/latex_templates/Test-amq_article/Test-amq_article.pdfsync +3397 -0
- data/examples/latex_templates/Test-amq_article/pics/Figure2.pdf +0 -0
- data/examples/latex_templates/Test-ams_article/Test-ams_article.Rmd +215 -0
- data/examples/latex_templates/Test-ams_article/amstest.bib +436 -0
- data/examples/latex_templates/Test-asa_article/Test-asa_article.Rmd +153 -0
- data/examples/latex_templates/Test-asa_article/Test-asa_article.pdf +0 -0
- data/examples/latex_templates/Test-asa_article/agsm.bst +1353 -0
- data/examples/latex_templates/Test-asa_article/bibliography.bib +233 -0
- data/examples/latex_templates/Test-ieee_article/IEEEtran.bst +2409 -0
- data/examples/latex_templates/Test-ieee_article/IEEEtran.cls +6346 -0
- data/examples/latex_templates/Test-ieee_article/Test-ieee_article.Rmd +175 -0
- data/examples/latex_templates/Test-ieee_article/Test-ieee_article.pdf +0 -0
- data/examples/latex_templates/Test-ieee_article/mybibfile.bib +20 -0
- data/examples/latex_templates/Test-rjournal_article/RJournal.sty +335 -0
- data/examples/latex_templates/Test-rjournal_article/RJreferences.bib +18 -0
- data/examples/latex_templates/Test-rjournal_article/RJwrapper.pdf +0 -0
- data/examples/latex_templates/Test-rjournal_article/Test-rjournal_article.Rmd +52 -0
- data/examples/latex_templates/Test-springer_article/Test-springer_article.Rmd +65 -0
- data/examples/latex_templates/Test-springer_article/Test-springer_article.pdf +0 -0
- data/examples/latex_templates/Test-springer_article/bibliography.bib +26 -0
- data/examples/latex_templates/Test-springer_article/spbasic.bst +1658 -0
- data/examples/latex_templates/Test-springer_article/spmpsci.bst +1512 -0
- data/examples/latex_templates/Test-springer_article/spphys.bst +1443 -0
- data/examples/latex_templates/Test-springer_article/svglov3.clo +113 -0
- data/examples/latex_templates/Test-springer_article/svjour3.cls +1431 -0
- data/examples/misc/moneyball.rb +1 -1
- data/examples/misc/subsetting.rb +37 -37
- data/examples/rmarkdown/svm-rmarkdown-anon-ms-example/svm-rmarkdown-anon-ms-example.Rmd +73 -0
- data/examples/rmarkdown/svm-rmarkdown-anon-ms-example/svm-rmarkdown-anon-ms-example.pdf +0 -0
- data/examples/rmarkdown/svm-rmarkdown-article-example/svm-rmarkdown-article-example.Rmd +382 -0
- data/examples/rmarkdown/svm-rmarkdown-article-example/svm-rmarkdown-article-example.pdf +0 -0
- data/examples/rmarkdown/svm-rmarkdown-beamer-example/svm-rmarkdown-beamer-example.Rmd +164 -0
- data/examples/rmarkdown/svm-rmarkdown-beamer-example/svm-rmarkdown-beamer-example.pdf +0 -0
- data/examples/rmarkdown/svm-rmarkdown-cv/svm-rmarkdown-cv.Rmd +92 -0
- data/examples/rmarkdown/svm-rmarkdown-cv/svm-rmarkdown-cv.pdf +0 -0
- data/examples/rmarkdown/svm-rmarkdown-syllabus-example/attend-grade-relationships.csv +482 -0
- data/examples/rmarkdown/svm-rmarkdown-syllabus-example/svm-rmarkdown-syllabus-example.Rmd +280 -0
- data/examples/rmarkdown/svm-rmarkdown-syllabus-example/svm-rmarkdown-syllabus-example.pdf +0 -0
- data/examples/rmarkdown/svm-xaringan-example/svm-xaringan-example.Rmd +386 -0
- data/lib/R_interface/r.rb +2 -2
- data/lib/R_interface/r_libs.R +6 -1
- data/lib/R_interface/r_methods.rb +12 -2
- data/lib/R_interface/rdata_frame.rb +8 -17
- data/lib/R_interface/rindexed_object.rb +1 -2
- data/lib/R_interface/rlist.rb +1 -0
- data/lib/R_interface/robject.rb +20 -23
- data/lib/R_interface/rpkg.rb +15 -6
- data/lib/R_interface/rsupport.rb +13 -19
- data/lib/R_interface/ruby_extensions.rb +14 -18
- data/lib/R_interface/rvector.rb +0 -12
- data/lib/gknit.rb +2 -0
- data/lib/gknit/draft.rb +105 -0
- data/lib/gknit/knitr_engine.rb +6 -37
- data/lib/util/exec_ruby.rb +22 -84
- data/lib/util/inline_file.rb +7 -3
- data/specs/figures/bg.jpeg +0 -0
- data/specs/figures/bg.png +0 -0
- data/specs/figures/bg.svg +2 -2
- data/specs/figures/dose_len.png +0 -0
- data/specs/figures/no_args.jpeg +0 -0
- data/specs/figures/no_args.png +0 -0
- data/specs/figures/no_args.svg +2 -2
- data/specs/figures/width_height.jpeg +0 -0
- data/specs/figures/width_height.png +0 -0
- data/specs/figures/width_height_units1.jpeg +0 -0
- data/specs/figures/width_height_units1.png +0 -0
- data/specs/figures/width_height_units2.jpeg +0 -0
- data/specs/figures/width_height_units2.png +0 -0
- data/specs/r_dataframe.spec.rb +184 -11
- data/specs/r_list.spec.rb +4 -4
- data/specs/r_list_apply.spec.rb +11 -10
- data/specs/ruby_expression.spec.rb +3 -11
- data/specs/tmp.rb +106 -34
- data/version.rb +1 -1
- metadata +96 -33
- data/bin/gknit_old_r +0 -236
- data/blogs/dev/dev.Rmd +0 -77
- data/blogs/dev/dev.md +0 -87
- data/blogs/dev/dev_files/figure-html/bubble-1.png +0 -0
- data/blogs/dev/dev_files/figure-html/diverging_bar. +0 -0
- data/blogs/dev/dev_files/figure-html/diverging_bar.png +0 -0
- data/blogs/dplyr/dplyr.rb +0 -63
- data/blogs/galaaz_ggplot/galaaz_ggplot.aux +0 -43
- data/blogs/galaaz_ggplot/galaaz_ggplot.log +0 -640
- data/blogs/galaaz_ggplot/galaaz_ggplot.out +0 -10
- data/blogs/galaaz_ggplot/galaaz_ggplot.tex +0 -481
- data/blogs/galaaz_ggplot/midwest.png +0 -0
- data/blogs/galaaz_ggplot/scatter_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot.Rmd_external_figs +0 -662
- data/blogs/ruby_plot/ruby_plot.tex +0 -1077
- data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.svg +0 -57
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_delivery.svg +0 -106
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_dose.svg +0 -110
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color.svg +0 -174
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color2.svg +0 -236
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.svg +0 -296
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_points.svg +0 -236
- data/blogs/ruby_plot/ruby_plot_files/figure-html/final_box_plot.svg +0 -218
- data/blogs/ruby_plot/ruby_plot_files/figure-html/final_violin_plot.svg +0 -128
- data/blogs/ruby_plot/ruby_plot_files/figure-html/violin_with_jitter.svg +0 -150
- data/examples/paper/paper.rb +0 -36
data/lib/R_interface/r.rb
CHANGED
@@ -23,7 +23,7 @@
|
|
23
23
|
|
24
24
|
# Load required R libraries
|
25
25
|
dir = File.dirname(File.expand_path('.', __FILE__))
|
26
|
-
Polyglot.eval_file("#{dir}/r_libs.R")
|
26
|
+
Polyglot.eval_file('R', "#{dir}/r_libs.R")
|
27
27
|
|
28
28
|
require_relative 'robject'
|
29
29
|
require_relative 'rsupport'
|
@@ -64,7 +64,7 @@ module R
|
|
64
64
|
|
65
65
|
def self.install_rlibs(*libs)
|
66
66
|
|
67
|
-
packages = R.c(libs)
|
67
|
+
packages = R.c(*libs)
|
68
68
|
|
69
69
|
new_packages = packages[!(packages._ :in, R.installed__packages[:all, "Package"])]
|
70
70
|
|
data/lib/R_interface/r_libs.R
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
-
list.of.packages <- c('rlang', 'purrr', 'formula.tools', 'lobstr')
|
1
|
+
list.of.packages <- c('rlang', 'purrr', 'formula.tools', 'lobstr', 'rticles')
|
2
2
|
|
3
3
|
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
|
4
4
|
if(length(new.packages)) install.packages(new.packages)
|
5
5
|
|
6
|
+
if (!('data.table' %in% installed.packages()[, "Package"])) {
|
7
|
+
install.fastr.packages('data.table')
|
8
|
+
}
|
9
|
+
|
6
10
|
library('formula.tools')
|
7
11
|
library('lobstr')
|
8
12
|
library('rlang')
|
9
13
|
library('purrr')
|
14
|
+
|
@@ -80,8 +80,8 @@ module R
|
|
80
80
|
|
81
81
|
def self.dbk_index
|
82
82
|
Polyglot.eval("R", <<-R)
|
83
|
-
function(obj,
|
84
|
-
obj[[
|
83
|
+
function(obj, ...) {
|
84
|
+
obj[[...]]
|
85
85
|
}
|
86
86
|
R
|
87
87
|
end
|
@@ -171,6 +171,16 @@ module R
|
|
171
171
|
R
|
172
172
|
end
|
173
173
|
|
174
|
+
#--------------------------------------------------------------------------------------
|
175
|
+
#
|
176
|
+
#--------------------------------------------------------------------------------------
|
177
|
+
|
178
|
+
Polyglot.eval("R", <<-R)
|
179
|
+
plot = function(...) {
|
180
|
+
print("Function 'plot' is not implemented in fastR. Please, use ggplot instead")
|
181
|
+
}
|
182
|
+
R
|
183
|
+
|
174
184
|
end
|
175
185
|
|
176
186
|
end
|
@@ -23,9 +23,9 @@
|
|
23
23
|
|
24
24
|
module R
|
25
25
|
|
26
|
-
class DataFrame <
|
26
|
+
class DataFrame < Object
|
27
|
+
include IndexedObject
|
27
28
|
include MDIndexedObject
|
28
|
-
include Enumerable
|
29
29
|
|
30
30
|
#--------------------------------------------------------------------------------------
|
31
31
|
# Calls the R.qplot adding the data: parameter
|
@@ -51,13 +51,16 @@ module R
|
|
51
51
|
# values, for ex., R.c(2, 3, 5)
|
52
52
|
#--------------------------------------------------------------------------------------
|
53
53
|
|
54
|
-
def []=(index,
|
55
|
-
|
54
|
+
def []=(index, *args)
|
55
|
+
values = args[-1]
|
56
|
+
idx2 = (args.size > 1)? args[-2] : false
|
57
|
+
|
56
58
|
# dealing with double indexing function '[['
|
57
59
|
if (index.is_a? Array)
|
58
60
|
setR_name("`[[<-`", R.empty_symbol, *index, values)
|
59
61
|
else
|
60
|
-
setR_name("`[<-`",
|
62
|
+
idx2 ? setR_name("`[<-`", index, idx2, values) :
|
63
|
+
setR_name("`[<-`", R.empty_symbol, index, values)
|
61
64
|
end
|
62
65
|
|
63
66
|
self
|
@@ -94,18 +97,6 @@ module R
|
|
94
97
|
|
95
98
|
end
|
96
99
|
|
97
|
-
#=begin
|
98
|
-
#--------------------------------------------------------------------------------------
|
99
|
-
# @TODO Need to understand why to_ary is being called here and what the effect is of
|
100
|
-
# returning the empty array. For now, doing this returns better error messages in
|
101
|
-
# rspec
|
102
|
-
#--------------------------------------------------------------------------------------
|
103
|
-
|
104
|
-
def to_ary
|
105
|
-
[]
|
106
|
-
end
|
107
|
-
#=end
|
108
|
-
|
109
100
|
end
|
110
101
|
|
111
102
|
end
|
@@ -38,8 +38,7 @@ module R
|
|
38
38
|
|
39
39
|
# dealing with double indexing function '[['
|
40
40
|
if (index.is_a? Array)
|
41
|
-
R::Support.exec_function(R::Support.dbk_index, @r_interop,
|
42
|
-
R.internal_eval(:c, *index))
|
41
|
+
R::Support.exec_function(R::Support.dbk_index, @r_interop, *index)
|
43
42
|
else
|
44
43
|
R::Support.exec_function_name("`[`", @r_interop, index)
|
45
44
|
end
|
data/lib/R_interface/rlist.rb
CHANGED
data/lib/R_interface/robject.rb
CHANGED
@@ -65,16 +65,6 @@ module R
|
|
65
65
|
R::Support.exec_function_name("`==`", @r_interop,
|
66
66
|
R::Support.parse_arg(other_object))
|
67
67
|
end
|
68
|
-
|
69
|
-
#--------------------------------------------------------------------------------------
|
70
|
-
# @TODO: rspec sometimes calls to_ary when an expected value is false. I still don't
|
71
|
-
# understand this call. Returning an array with a number inside seems to make
|
72
|
-
# rspec happy, however this could have other consequences I don't know of.
|
73
|
-
#--------------------------------------------------------------------------------------
|
74
|
-
|
75
|
-
def to_ary
|
76
|
-
[1]
|
77
|
-
end
|
78
68
|
|
79
69
|
#--------------------------------------------------------------------------------------
|
80
70
|
# @param r_interop [Interop] pointer to an R object
|
@@ -133,29 +123,28 @@ module R
|
|
133
123
|
end
|
134
124
|
|
135
125
|
end
|
136
|
-
|
137
|
-
=begin
|
138
|
-
#--------------------------------------------------------------------------------------
|
139
|
-
# This method was moved to DataFrame. Need to check which other objects can have
|
140
|
-
# values assigned to them
|
141
|
-
#--------------------------------------------------------------------------------------
|
142
126
|
|
143
|
-
def method_missing_assign(column_name, arg)
|
144
|
-
return setR_name("`[<-`", R.empty_symbol, column_name, arg)
|
145
|
-
end
|
146
|
-
=end
|
147
127
|
#--------------------------------------------------------------------------------------
|
148
128
|
#
|
149
129
|
#--------------------------------------------------------------------------------------
|
150
130
|
|
151
131
|
def method_missing(symbol, *args, &block)
|
152
|
-
|
153
132
|
name = R::Support.convert_symbol2r(symbol)
|
154
133
|
|
155
134
|
# Need to raise a NoMethodError when method_missing is called by an implicit
|
156
|
-
# call to "to_ary".
|
135
|
+
# call to "to_ary". The explanation for that is:
|
136
|
+
# Okay, I've found the source of the behaviour. IOOperations.puts will attempt to
|
137
|
+
# coerce an argument to an array and print its contents, and R::Vector responds to
|
138
|
+
# to_ary but returns the empty array which results in no output.
|
139
|
+
#
|
140
|
+
# Previously IOOperations.puts only checked the type of the argument, and did not
|
141
|
+
# attempt coercion, but that meant we didn't match MRI's behaviour and had some test
|
142
|
+
# failures in other gems. I'd suggest either removing the to_ary methods on
|
143
|
+
# R::Object and R::Vector or implementing them more fully. I see from the comments on
|
144
|
+
# those methods that you needed them for RSpec, it might worth seeing if those problems
|
145
|
+
# still occur and we can look a better way to resolve those.
|
157
146
|
raise NoMethodError if name == "to_ary"
|
158
|
-
|
147
|
+
|
159
148
|
case
|
160
149
|
when block_given?
|
161
150
|
R::Support.new_scope(symbol, self, *args, &block)
|
@@ -331,6 +320,14 @@ module R
|
|
331
320
|
#
|
332
321
|
#--------------------------------------------------------------------------------------
|
333
322
|
|
323
|
+
def pretty_print(obj)
|
324
|
+
puts self
|
325
|
+
end
|
326
|
+
|
327
|
+
#--------------------------------------------------------------------------------------
|
328
|
+
#
|
329
|
+
#--------------------------------------------------------------------------------------
|
330
|
+
|
334
331
|
def to_s
|
335
332
|
|
336
333
|
begin
|
data/lib/R_interface/rpkg.rb
CHANGED
@@ -28,16 +28,26 @@ module R
|
|
28
28
|
#
|
29
29
|
#----------------------------------------------------------------------------------------
|
30
30
|
|
31
|
-
class
|
31
|
+
class Package
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
@@packages = {}
|
34
|
+
|
35
|
+
def self.[](package_name)
|
36
|
+
return @@packages[package_name] if @@packages.has_key?(package_name)
|
37
|
+
@@packages[package_name] = new(package_name)
|
35
38
|
end
|
36
39
|
|
40
|
+
def initialize(package_name)
|
41
|
+
@package_name = package_name
|
42
|
+
end
|
43
|
+
|
37
44
|
def method_missing(symbol, *args)
|
38
|
-
|
45
|
+
symbol = R::Support.convert_symbol2r(symbol)
|
46
|
+
R::Support.exec_function_name("#{@package_name}::#{symbol}", *args)
|
39
47
|
end
|
40
48
|
|
49
|
+
private_class_method :new
|
50
|
+
|
41
51
|
end
|
42
52
|
|
43
53
|
#----------------------------------------------------------------------------------------
|
@@ -45,8 +55,7 @@ module R
|
|
45
55
|
#----------------------------------------------------------------------------------------
|
46
56
|
|
47
57
|
def self.const_missing(name)
|
48
|
-
|
49
|
-
Pkg.new(name)
|
58
|
+
R::Package[name.to_s.downcase]
|
50
59
|
end
|
51
60
|
|
52
61
|
end
|
data/lib/R_interface/rsupport.rb
CHANGED
@@ -29,7 +29,7 @@ module R
|
|
29
29
|
# as [x, ]. What follows the ',' is an empty_symbol. Whenever we use in Ruby the
|
30
30
|
# :all symbol, it will be converted to an empty_symbol in R.
|
31
31
|
#--------------------------------------------------------------------------------------
|
32
|
-
|
32
|
+
=begin
|
33
33
|
@@empty_symbol = Polyglot.eval("R", <<-R)
|
34
34
|
__missing_arg = quote(f(,0));
|
35
35
|
__missing_arg[[2]]
|
@@ -38,7 +38,12 @@ module R
|
|
38
38
|
def self.empty_symbol
|
39
39
|
@@empty_symbol
|
40
40
|
end
|
41
|
+
=end
|
41
42
|
|
43
|
+
def self.empty_symbol
|
44
|
+
Polyglot.eval("R", "missing_arg()")
|
45
|
+
end
|
46
|
+
|
42
47
|
# When evaluating to NA, Interop treats it as FALSE. This breaks all expectations
|
43
48
|
# about NA. We need to protect NA from Interop unboxing. Class NotAvailable
|
44
49
|
# puts a list around NA, so that no unboxing occurs.
|
@@ -63,24 +68,17 @@ module R
|
|
63
68
|
# and allows for debugging. Use it in exec_function when debugging is needed.
|
64
69
|
@@exec_from_ruby = Polyglot.eval("R", <<-R)
|
65
70
|
function(build_method, ...) {
|
66
|
-
# print(build_method);
|
67
|
-
# print("exec_from_ruby");
|
68
|
-
# args = list(...);
|
69
|
-
# print(args);
|
70
|
-
|
71
71
|
# function 'invoke' from package rlang should do a cleaner than
|
72
72
|
# do.call (this is what the documentation says).
|
73
73
|
# res = do.call(...);
|
74
74
|
res = invoke(...);
|
75
|
-
|
76
|
-
# print(res);
|
77
75
|
res2 = build_method(res);
|
78
|
-
# print(res2);
|
79
76
|
res2
|
80
77
|
}
|
81
78
|
R
|
82
79
|
|
83
80
|
#----------------------------------------------------------------------------------------
|
81
|
+
# @TODO: Fix the 'rescue' clause and open issue with fastR
|
84
82
|
# Evaluates an R code
|
85
83
|
# @param string [String] A string of R code that can be correctly parsed by R
|
86
84
|
#----------------------------------------------------------------------------------------
|
@@ -211,8 +209,6 @@ module R
|
|
211
209
|
|
212
210
|
#----------------------------------------------------------------------------------------
|
213
211
|
# @param function [R function (Interop)] R function to execute
|
214
|
-
# @param internal [Boolean] true if returning to an internal object, i.e., does not
|
215
|
-
# wrap the return object in a Ruby object
|
216
212
|
# @args [Array] Array of arguments for the function
|
217
213
|
#----------------------------------------------------------------------------------------
|
218
214
|
|
@@ -237,28 +233,26 @@ module R
|
|
237
233
|
res = @@exec_from_ruby.call(R::Object.method(:build), function, pl)
|
238
234
|
# R::Object.build(R::Support.eval("do.call").call(function, pl))
|
239
235
|
end
|
240
|
-
|
236
|
+
|
241
237
|
@@exec_counter = @@exec_counter - 1
|
242
238
|
|
243
239
|
# When execution counter back to 0, print the captured output if the length
|
244
240
|
# of the output is greater than 0
|
245
241
|
if (@@exec_counter == 0)
|
246
242
|
R::Support.stop_capture.call(@@con)
|
247
|
-
=begin
|
248
243
|
if (R::Support.eval("length(r_capture) > 0")[0])
|
249
244
|
cap = R::Object.build(R::Support.eval("r_capture"))
|
250
245
|
(0...cap.size).each do |i|
|
251
|
-
puts cap
|
246
|
+
puts cap >> i
|
252
247
|
end
|
253
248
|
end
|
254
|
-
=end
|
255
249
|
end
|
256
|
-
|
250
|
+
|
257
251
|
rescue StandardError => e
|
258
|
-
R::Support.stop_capture.call(@@con)
|
252
|
+
R::Support.stop_capture.call(@@con) if (@@exec_counter == 0)
|
259
253
|
raise e
|
260
254
|
end
|
261
|
-
|
255
|
+
|
262
256
|
res
|
263
257
|
|
264
258
|
end
|
@@ -270,7 +264,7 @@ module R
|
|
270
264
|
|
271
265
|
def self.exec_function_name(function_name, *args)
|
272
266
|
# @TODO: should check all that can go wrong when calling eval(function_name) to
|
273
|
-
# raise the proper exception
|
267
|
+
# raise the proper exception
|
274
268
|
f = R::Support.eval(function_name)
|
275
269
|
R::Support.exec_function(f, *args)
|
276
270
|
end
|
@@ -161,14 +161,6 @@ class Symbol
|
|
161
161
|
def assign2(expression)
|
162
162
|
exec_bin_oper("`=`", expression)
|
163
163
|
end
|
164
|
-
|
165
|
-
#--------------------------------------------------------------------------------------
|
166
|
-
#
|
167
|
-
#--------------------------------------------------------------------------------------
|
168
|
-
|
169
|
-
def [](index)
|
170
|
-
exec_bin_oper("`[[`", index)
|
171
|
-
end
|
172
164
|
|
173
165
|
#--------------------------------------------------------------------------------------
|
174
166
|
#
|
@@ -176,18 +168,22 @@ class Symbol
|
|
176
168
|
|
177
169
|
def method_missing(symbol, *args, &block)
|
178
170
|
|
179
|
-
|
180
|
-
# method_missing_assign($1, args[0])
|
181
|
-
elsif (args.length == 0 && ((R.c(symbol.to_s)._ :in, R.names(self)) >> 0))
|
182
|
-
return self[symbol.to_s]
|
183
|
-
end
|
184
|
-
|
185
|
-
R.send(symbol.to_s, self, *args)
|
171
|
+
E.send(symbol.to_s, self, *args)
|
186
172
|
|
187
173
|
end
|
188
174
|
|
189
175
|
#--------------------------------------------------------------------------------------
|
190
|
-
#
|
176
|
+
# Used when selecting column in a data frame, from the first column to the var2
|
177
|
+
# column
|
178
|
+
#--------------------------------------------------------------------------------------
|
179
|
+
|
180
|
+
def up_to(var2)
|
181
|
+
R::Support.exec_function(R::Support.range, self, var2)
|
182
|
+
end
|
183
|
+
|
184
|
+
|
185
|
+
#--------------------------------------------------------------------------------------
|
186
|
+
# Create an interaction between two variables in formulas
|
191
187
|
#--------------------------------------------------------------------------------------
|
192
188
|
|
193
189
|
def inter(var2)
|
@@ -204,7 +200,7 @@ class Symbol
|
|
204
200
|
#--------------------------------------------------------------------------------------
|
205
201
|
|
206
202
|
def to_ary
|
207
|
-
[self.to_s]
|
203
|
+
# [self.to_s]
|
208
204
|
end
|
209
|
-
|
205
|
+
|
210
206
|
end
|
data/lib/R_interface/rvector.rb
CHANGED
@@ -115,18 +115,6 @@ module R
|
|
115
115
|
puts "comparison called"
|
116
116
|
end
|
117
117
|
|
118
|
-
#=begin
|
119
|
-
#--------------------------------------------------------------------------------------
|
120
|
-
# @TODO Need to understand why to_ary is being called here and what the effect is of
|
121
|
-
# returning the empty array. For now, doing this returns better error messages in
|
122
|
-
# rspec
|
123
|
-
#--------------------------------------------------------------------------------------
|
124
|
-
|
125
|
-
def to_ary
|
126
|
-
[]
|
127
|
-
end
|
128
|
-
#=end
|
129
|
-
|
130
118
|
end
|
131
119
|
|
132
120
|
end
|
data/lib/gknit.rb
CHANGED
data/lib/gknit/draft.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
##########################################################################################
|
4
|
+
# @author Rodrigo Botafogo
|
5
|
+
#
|
6
|
+
# Copyright © 2018 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
|
7
|
+
# and distribute this software and its documentation, without fee and without a signed
|
8
|
+
# licensing agreement, is hereby granted, provided that the above copyright notice, this
|
9
|
+
# paragraph and the following two paragraphs appear in all copies, modifications, and
|
10
|
+
# distributions.
|
11
|
+
#
|
12
|
+
# IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
13
|
+
# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
14
|
+
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
|
15
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
16
|
+
#
|
17
|
+
# RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
18
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
19
|
+
# SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
|
20
|
+
# RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
21
|
+
# OR MODIFICATIONS.
|
22
|
+
##########################################################################################
|
23
|
+
|
24
|
+
module GKnit
|
25
|
+
|
26
|
+
#--------------------------------------------------------------------------------------
|
27
|
+
#
|
28
|
+
#--------------------------------------------------------------------------------------
|
29
|
+
|
30
|
+
Polyglot.eval("R", <<-R)
|
31
|
+
ruby_template = function(gem, family, template, type, ...) {
|
32
|
+
print(gem)
|
33
|
+
print(family)
|
34
|
+
print(template)
|
35
|
+
print(type)
|
36
|
+
data_dir = eval.polyglot("ruby", "GKnit")$template_path(gem, family, template)
|
37
|
+
print(data_dir)
|
38
|
+
invoke(type, list(template = "template.tex", pandoc_args = paste0("--data-dir=", data_dir), ...))
|
39
|
+
}
|
40
|
+
R
|
41
|
+
|
42
|
+
#--------------------------------------------------------------------------------------
|
43
|
+
#
|
44
|
+
#--------------------------------------------------------------------------------------
|
45
|
+
|
46
|
+
def self.template_path(gem, family, template)
|
47
|
+
full_filename = Dir.glob("gknit-templates*", base: "#{Gem.default_dir}/gems")
|
48
|
+
template_path = "#{Gem.default_dir}/gems/#{full_filename[0]}/#{family}/#{template}"
|
49
|
+
end
|
50
|
+
|
51
|
+
#--------------------------------------------------------------------------------------
|
52
|
+
#
|
53
|
+
#--------------------------------------------------------------------------------------
|
54
|
+
|
55
|
+
def self.draft(file:, template:, package: nil,
|
56
|
+
create_dir: 'default', is_package: true, edit: true)
|
57
|
+
|
58
|
+
# ignore the file extension if given. It should always be an .Rmd file
|
59
|
+
file_basename = File.basename(file, File.extname(file))
|
60
|
+
file = "#{file_basename}.Rmd"
|
61
|
+
|
62
|
+
# resolve package file
|
63
|
+
# TODO: if package is a rubygem, then look there somehow
|
64
|
+
if (is_package)
|
65
|
+
template_path =
|
66
|
+
R.system__file("rmarkdown", "templates", template, package: package) >> 0
|
67
|
+
raise "The template '#{template}' was not found in the package '#{package}'" if
|
68
|
+
!(R.nzchar(template_path) >> 0)
|
69
|
+
else
|
70
|
+
full_filename = Dir.glob("gknit-templates*", base: "#{Gem.default_dir}/gems")
|
71
|
+
template_path = "#{Gem.default_dir}/gems/#{full_filename[0]}/#{template}"
|
72
|
+
puts template_path
|
73
|
+
# raise "this is not an R package"
|
74
|
+
end
|
75
|
+
|
76
|
+
# read the template.yaml and confirm it has the right fields
|
77
|
+
template_yaml = File.expand_path("template.yaml", template_path)
|
78
|
+
raise "No 'template.yaml' file found for template '#{template}" if
|
79
|
+
!File.file?(template_yaml)
|
80
|
+
|
81
|
+
template_meta = R::Yaml::yaml__load(R.read_utf8(template_yaml))
|
82
|
+
raise "template.yaml must contain 'name' and 'description' fields" if
|
83
|
+
(template_meta.name.is__null || template_meta.description.is__null) >> 0
|
84
|
+
puts "Creating template:"
|
85
|
+
puts "Template name: #{template_meta.name >> 0}"
|
86
|
+
puts "Description: #{template_meta.description >> 0}"
|
87
|
+
|
88
|
+
if (create_dir == 'default')
|
89
|
+
# check if template asks for new directory
|
90
|
+
create_dir = template_meta.create_dir.isTRUE >> 0
|
91
|
+
|
92
|
+
if (create_dir)
|
93
|
+
raise "The directory '#{file_basename}' already exists" if Dir.exist?(file_basename)
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
raise "File #{file} already exists" if File.file?("#{file_basename}/#{file}")
|
99
|
+
FileUtils.cp_r("#{template_path}/skeleton", "#{file_basename}")
|
100
|
+
# FileUtils.cp("#{template_path}/resources/template.tex", "#{file_basename}")
|
101
|
+
File.rename("#{file_basename}/skeleton.Rmd", "#{file_basename}/#{file}")
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|