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
data/Rakefile CHANGED
@@ -33,7 +33,10 @@ require_relative 'version'
33
33
  class MakeTask < Rake::TaskLib
34
34
 
35
35
  # Create class variables for the polyglot options and libs
36
- @@polyglot_options = "--polyglot --jvm -Xsingle_threaded"
36
+ # not yet possible to run native with R it seems...
37
+ # @@polyglot_options = "--polyglot --experimental-options --single_threaded"
38
+ # @@polyglot_options = "--polyglot --jvm --experimental-options --single-threaded"
39
+ @@polyglot_options = "--polyglot --jvm"
37
40
  @@libs = "-Ilib/" # -Ir_requires/"
38
41
 
39
42
  #----------------------------------------------------------------------------------------
@@ -74,12 +77,16 @@ class MakeTask < Rake::TaskLib
74
77
 
75
78
  end
76
79
 
80
+
81
+ task :default => "sthda:all"
82
+
77
83
  geoms = FileList['examples/sthda_ggplot/**/*.rb']
78
84
  specs = FileList['specs/**/*.rb']
79
85
  master_list = FileList['examples/50Plots_MasterList/**/*.rb']
80
86
  islr = FileList['examples/islr/**/*.rb']
81
87
  misc = FileList['examples/misc/**/*.rb']
82
88
  blogs = Dir.entries("blogs")
89
+ bugs = FileList['bugs/**/*.rb']
83
90
 
84
91
  #===========================================================================================
85
92
  # Creates tasks for all specs.
@@ -146,7 +153,17 @@ misc.each do |f|
146
153
  Desc
147
154
  end
148
155
 
149
- task :default => "sthda:all"
156
+ #===========================================================================================
157
+ # Creates tasks for bug examples
158
+ #===========================================================================================
159
+
160
+ bugs.each do |f|
161
+ task_name = File.basename(f, ".rb")
162
+ dir_name = File.dirname(f)
163
+ MakeTask.new("bugs", dir_name, task_name, false, <<-Desc)
164
+ Executes misc #{task_name}
165
+ Desc
166
+ end
150
167
 
151
168
  #===========================================================================================
152
169
  # Creates task for running gknit
@@ -157,11 +174,11 @@ blogs.each do |dir|
157
174
  blog_rmd = "blogs/#{dir}/#{dir}.Rmd"
158
175
  desc "run gknit to build #{dir} blog post"
159
176
  task "blog:#{dir}" do
160
- (sh %{ bin/gknit #{blog_rmd} })
177
+ (sh %{ bin/gknit #{blog_rmd} } )
161
178
  end
162
179
 
163
180
  end
164
-
181
+
165
182
  #===========================================================================================
166
183
  # Loads R and require libraries to run Galaaz
167
184
  #===========================================================================================
data/bin/gknit CHANGED
@@ -1,15 +1,161 @@
1
1
  #!/usr/bin/env ruby
2
2
  # coding: utf-8
3
3
 
4
+ require 'optionparser'
5
+
6
+ options = {}
7
+
8
+ OptionParser.new do |opts|
9
+ opts.banner = "Usage: gknit [options]"
10
+ opts.on("-f", "--filename FILE", "The input file to be rendered.
11
+ This value can also be provided without the '-f' or '--filename'
12
+ flag by just giving the name of the file as an input parameter.") do |opt|
13
+ options[:input_file] = opt
14
+ end
15
+ opts.on("--output_format OUT_FORMAT",
16
+ "The R Markdown output format to convert to. The option 'all'
17
+ will render all formats defined within the file. The option
18
+ can be the name of a format (e.g. 'html_document') and that
19
+ will render the document to that single format. One can also
20
+ use a vector of format names to render to multiple formats.
21
+ Alternatively, you can pass an output format object (e.g.
22
+ html_document()). If using NULL then the output format is the
23
+ first one defined in the YAML frontmatter in the input file
24
+ (this defaults to HTML if no format is specified there).") do |opt|
25
+ options[:output_format] = opt
26
+ end
27
+ opts.on("-o", "--output_file OUT_FILE", "The name of the output file.
28
+ If using nil then the output filename will be based on filename for
29
+ the input file. If a filename is provided, a path to the output file
30
+ can also be provided. Note that the output_dir option allows for
31
+ specifying the output file path as well, however, if also specifying
32
+ the path, the directory must exist.") do |opt|
33
+ options[:output_file] = opt
34
+ end
35
+ opts.on("-d", "--output_dir OUT_DIR", "The output directory for
36
+ the rendered output_file. This allows for a choice of an alternate
37
+ directory to which the output file should be written (the default
38
+ output directory is that of the input file). If a path is provided
39
+ with a filename in output_file the directory specified here will
40
+ take precedence. Please note that any directory path provided will
41
+ create any necessary directories if they do not exist.") do |opt|
42
+ options[:output_dir] = opt
43
+ end
44
+ opts.on("-a", "--output_options OUT_OPT", "List of output options
45
+ that can override the options specified in metadata (e.g. could be
46
+ used to force self_contained or mathjax = 'local'). Note that this
47
+ is only valid when the output format is read from metadata (i.e.
48
+ not a custom format object passed to output_format).") do |opt|
49
+ options[:output_options] = opt
50
+ end
51
+ opts.on("-i", "--intermediates_dir INTER_DIR", "FEATURE NOT YET
52
+ IMPLEMENTED! Intermediate files directory. If a path is specified
53
+ then intermediate files will be written to that path. If nil,
54
+ intermediate files are written to the same directory as the input
55
+ file.") do |opt|
56
+ options[:intermediates_dir] = opt
57
+ end
58
+ opts.on("-n", "--no_clean", "Will not clean intermediate files
59
+ that are created during rendering.") do |opt|
60
+ options[:clean] = opt
61
+ end
62
+ end.parse!
63
+
64
+ # Sets the directory
4
65
  dir = Dir.pwd
5
- puts "Knitting #{dir}/#{ARGV[0]}"
6
66
 
67
+ #=========================================================================================
68
+ # Check if the name of the file to gKnit was given and that it exists. If not,
69
+ # issue error.
70
+ #=========================================================================================
71
+
72
+ options[:input_file] = ARGV[0] if !ARGV[0].nil?
73
+ raise "Input file name is required for gKnitting. Add -f FILE or --input_file FILE. For help, type gknit -h" if
74
+ options[:input_file].nil?
75
+ options[:input_file] = "#{dir}/#{options[:input_file]}"
76
+ raise "File #{options[:input_file]} does not exist!" if !File.exist?(options[:input_file])
77
+
78
+ #=========================================================================================
79
+ # Checks the output_format option. If none, pass NULL to the render function. Output
80
+ # format needs to be quoted.
81
+ #=========================================================================================
82
+
83
+ options[:output_format] =
84
+ (options[:output_format].nil?)? "nil" : "\"#{options[:output_format]}\""
85
+
86
+ #=========================================================================================
87
+ # Checks the output_file option. If none, pass NULL to the render function. Output
88
+ # file name needs to be quoted.
89
+ #=========================================================================================
90
+
91
+ options[:output_file] =
92
+ (options[:output_file].nil?)? "nil" : "\"#{options[:output_file]}\""
93
+
94
+ #=========================================================================================
95
+ # Checks if an output directory was given. If given and directory does not exist,
96
+ # create the directory. If no directory given, pass NULL to the render function.
97
+ #=========================================================================================
98
+
99
+ if (!options[:output_dir].nil?)
100
+ Dir.mkdir(options[:output_dir]) if !Dir.exist?(options[:output_dir])
101
+ options[:output_dir] = "\"#{options[:output_dir]}\""
102
+ else
103
+ # If not, pass NULL to the render function
104
+ options[:output_dir] = "nil"
105
+ end
106
+
107
+ #=========================================================================================
108
+ # Checks if any intermediate directory given. If not, pass NULL to the render function
109
+ # Calling render with options intermediates_dir is not working, requires further study
110
+ #=========================================================================================
111
+
112
+ if (!options[:intermediates_dir].nil?)
113
+ if !Dir.exist?(options[:intermediates_dir])
114
+ Dir.mkdir(options[:intermediates_dir])
115
+ options[:intermediates_dir] = "\"#{options[:intermediates_dir]}\""
116
+ else
117
+ options[:intermediates_dir] = "\"#{options[:intermediates_dir]}\""
118
+ end
119
+ else
120
+ options[:intermediates_dir] = "nil"
121
+ end
122
+
123
+ options[:clean] = (options[:clean].nil?)? "true" : "false"
124
+
125
+ #=========================================================================================
126
+ # Sends message to user that the gKniting process has started
127
+ #=========================================================================================
128
+ puts "================================"
129
+ puts "gKnitting #{options[:input_file]} with the following options:"
130
+ puts " * Output format: \t #{options[:output_format]}"
131
+ puts " * Output file: \t #{options[:output_file]}"
132
+ puts " * Output directory: \t #{options[:output_dir]}"
133
+ puts " * Clean: \t\t #{options[:clean]}"
134
+
135
+
136
+ # Code to be evaluated by the polyglot Ruby script
7
137
  code = <<EOF
8
- eval.polyglot("ruby", "$LOAD_PATH.unshift %q(/home/rbotafogo/desenv/galaaz/lib)")
9
- eval.polyglot("ruby", "require %q(gknit)")
138
+ require %q(galaaz)
139
+ require %q(gknit)
10
140
 
11
- gknit_file = "#{dir}/#{ARGV[0]}"
12
- rmarkdown::render("#{dir}/#{ARGV[0]}")
141
+ R::Rmarkdown.render(
142
+ %q(#{options[:input_file]}),
143
+ output_format: #{options[:output_format]},
144
+ output_file: #{options[:output_file]},
145
+ output_dir: #{options[:output_dir]},
146
+ clean: #{options[:clean]}
147
+ )
13
148
  EOF
14
149
 
15
- exec "Rscript --jvm --polyglot -e '#{code}'"
150
+ libx = File.expand_path('../../lib', __FILE__)
151
+ exec "ruby --polyglot --jvm --experimental-options --single-threaded -I#{libx} -e '#{code}'"
152
+
153
+ =begin
154
+ # how to call rmarkdown::render with a parameter list
155
+ # all params need to be defined in the YAML header
156
+ rmarkdown::render("#{options[:input_file]}", output_format = #{options[:output_format]},
157
+ output_file = #{options[:output_file]},
158
+ output_dir = #{options[:output_dir]},
159
+ clean = #{options[:clean]},
160
+ params = list(rake_clean = TRUE))
161
+ =end
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ ##########################################################################################
5
+ # @author Rodrigo Botafogo
6
+ #
7
+ # Copyright © 2018 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
8
+ # and distribute this software and its documentation, without fee and without a signed
9
+ # licensing agreement, is hereby granted, provided that the above copyright notice, this
10
+ # paragraph and the following two paragraphs appear in all copies, modifications, and
11
+ # distributions.
12
+ #
13
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
14
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
15
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
16
+ # POSSIBILITY OF SUCH DAMAGE.
17
+ #
18
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
20
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
21
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
22
+ # OR MODIFICATIONS.
23
+ ##########################################################################################
24
+
25
+ require 'optionparser'
26
+
27
+ options = {}
28
+
29
+ OptionParser.new do |opts|
30
+ opts.banner = "Usage: gknit-draft [options] [path]"
31
+ opts.on("-f", "--filename FILE", "Directory and filename to create") do |opt|
32
+ options[:file] = opt
33
+ end
34
+ opts.on("-t", "--template TEMPLATE", "Latex template to use") do |opt|
35
+ options[:template] = opt
36
+ end
37
+ opts.on("-p", "--package PACKAGE", "R Package where the template is defined") do |opt|
38
+ options[:package] = opt
39
+ end
40
+ opts.on("-g", "--gem RubyGem", "Ruby Gem where the template is defined") do |opt|
41
+ options[:gem] = opt
42
+ end
43
+ opts.on("-n", "--no_dir", "If a new directory should not be created") do |opt|
44
+ options[:no_dir] = opt
45
+ end
46
+ opts.on("-e", "--edit EDITOR", "Editor to use to edit the file") do |opt|
47
+ options[:editor] = opt
48
+ end
49
+ end.parse!
50
+
51
+ #=========================================================================================
52
+ # Only one of 'package' or 'gem' can be given
53
+ #=========================================================================================
54
+
55
+ raise "You should either specify an R package or Ruby Gem where the template is defined" if
56
+ !options[:package].nil? && !options[:gem].nil?
57
+
58
+ #=========================================================================================
59
+ # If gem given, then set it as the package name
60
+ #=========================================================================================
61
+
62
+ is_r_package = (options[:package].nil?)? false : true
63
+ options[:package] =
64
+ (!options[:gem].nil?)? "%Q(#{options[:gem]})" : "%Q(#{options[:package]})"
65
+
66
+ #=========================================================================================
67
+ #
68
+ #=========================================================================================
69
+
70
+ options[:no_dir] = (options[:no_dir].nil?)? true : false
71
+
72
+ #=========================================================================================
73
+ #
74
+ #=========================================================================================
75
+
76
+ Dir.chdir(File.dirname(File.expand_path('.', __FILE__)))
77
+
78
+ options[:file] = "%Q(#{options[:file]}-#{options[:template]})"
79
+
80
+ code = <<-Ruby
81
+ require 'gknit'
82
+ R.install_and_loads 'xfun'
83
+
84
+ GKnit.draft(file: #{options[:file]}, template: %Q(#{options[:template]}),
85
+ package: #{options[:package]}, create_dir: #{options[:no_dir]},
86
+ is_package: #{is_r_package}, edit: true)
87
+ Ruby
88
+
89
+ libx = File.expand_path('../../lib', __FILE__)
90
+ exec %Q(ruby --polyglot --jvm -I#{libx} -e "#{code}")
91
+
92
+ # exec %Q(ruby --polyglot --jvm --experimental-options --single-threaded -I../lib -e "#{code}")
93
+
94
+ =begin
95
+ puts "=========="
96
+ full_filename = Dir.glob("gknit-templates*", base: "#{Gem.default_dir}/gems")
97
+ template_path = "#{Gem.default_dir}/gems/#{full_filename[0]/rmarkdown/templates/}"
98
+ puts template_path
99
+ puts "=========="
100
+ =end
101
+
102
+ #puts %Q(ruby --polyglot --jvm --experimental-options --single-threaded -I../lib -e "#{code}")
103
+
104
+ #exec "ruby --polyglot --jvm --experimental-options --single-threaded \
105
+ #-I../lib -S ./gknit-draft.rb #{options[:file]} #{options[:template]} #{options[:package]} #{options[:create_#dir]} #{is_r_package} #{options[:editor]}"
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ ##########################################################################################
3
+ # @author Rodrigo Botafogo
4
+ #
5
+ # Copyright © 2018 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
6
+ # and distribute this software and its documentation, without fee and without a signed
7
+ # licensing agreement, is hereby granted, provided that the above copyright notice, this
8
+ # paragraph and the following two paragraphs appear in all copies, modifications, and
9
+ # distributions.
10
+ #
11
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
12
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
13
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
14
+ # POSSIBILITY OF SUCH DAMAGE.
15
+ #
16
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
18
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
19
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
20
+ # OR MODIFICATIONS.
21
+ ##########################################################################################
22
+
23
+ require 'gknit'
24
+
25
+ R.install_and_loads 'xfun'
26
+
27
+ GKnit.draft(file: ARGV[0], template: ARGV[1], package: ARGV[2],
28
+ create_dir: ARGV[3], is_package: ARGV[4], edit: ARGV[5])
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require 'optionparser'
5
+
6
+ options = {}
7
+
8
+ OptionParser.new do |opts|
9
+ opts.banner = "Usage: gknit [options]"
10
+ opts.on("-f", "--filename FILE", "The input file to be rendered. This value can also be provided without the '-f' or '--filename' flag by just giving the name of the file as an input parameter.") do |opt|
11
+ options[:input_file] = opt
12
+ end
13
+ opts.on("--output_format OUT_FORMAT", "The R Markdown output format to convert to. The option 'all' will render all formats defined within the file. The option can be the name of a format (e.g. 'html_document') and that will render the document to that single format. One can also use a vector of format names to render to multiple formats. Alternatively, you can pass an output format object (e.g. html_document()). If using NULL then the output format is the first one defined in the YAML frontmatter in the input file (this defaults to HTML if no format is specified there).") do |opt|
14
+ options[:output_format] = opt
15
+ end
16
+ opts.on("-o", "--output_file OUT_FILE", "The name of the output file. If using nil then the output filename will be based on filename for the input file. If a filename is provided, a path to the output file can also be provided. Note that the output_dir option allows for specifying the output file path as well, however, if also specifying the path, the directory must exist.") do |opt|
17
+ options[:output_file] = opt
18
+ end
19
+ opts.on("-d", "--output_dir OUT_DIR", "The output directory for the rendered output_file. This allows for a choice of an alternate directory to which the output file should be written (the default output directory is that of the input file). If a path is provided with a filename in output_file the directory specified here will take precedence. Please note that any directory path provided will create any necessary directories if they do not exist.") do |opt|
20
+ options[:output_dir] = opt
21
+ end
22
+ opts.on("-a", "--output_options OUT_OPT", "List of output options that can override the options specified in metadata (e.g. could be used to force self_contained or mathjax = 'local'). Note that this is only valid when the output format is read from metadata (i.e. not a custom format object passed to output_format).") do |opt|
23
+ options[:output_options] = opt
24
+ end
25
+ opts.on("-i", "--intermediates_dir INTER_DIR", "FEATURE NOT YET IMPLEMENTED! Intermediate files directory. If a path is specified then intermediate files will be written to that path. If nil, intermediate files are written to the same directory as the input file.") do |opt|
26
+ options[:intermediates_dir] = opt
27
+ end
28
+ opts.on("-n", "--no_clean", "Will not clean intermediate files that are created during rendering.") do |opt|
29
+ options[:clean] = opt
30
+ end
31
+ end.parse!
32
+
33
+ # Sets the directory
34
+ dir = Dir.pwd
35
+
36
+ #=========================================================================================
37
+ # Check if the name of the file to gKnit was given and that it exists. If not,
38
+ # issue error.
39
+ #=========================================================================================
40
+
41
+ options[:input_file] = ARGV[0] if !ARGV[0].nil?
42
+ raise "Input file name is required for gKnitting. Add -f FILE or --input_file FILE. For help, type gknit -h" if
43
+ options[:input_file].nil?
44
+ options[:input_file] = "#{dir}/#{options[:input_file]}"
45
+ raise "File #{options[:input_file]} does not exist!" if !File.exist?(options[:input_file])
46
+
47
+ #=========================================================================================
48
+ # Checks the output_format option. If none, pass NULL to the render function. Output
49
+ # format needs to be quoted.
50
+ #=========================================================================================
51
+
52
+ options[:output_format] =
53
+ (options[:output_format].nil?)? "NULL" : "\"#{options[:output_format]}\""
54
+
55
+ #=========================================================================================
56
+ # Checks the output_file option. If none, pass NULL to the render function. Output
57
+ # file name needs to be quoted.
58
+ #=========================================================================================
59
+
60
+ options[:output_file] =
61
+ (options[:output_file].nil?)? "NULL" : "\"#{options[:output_file]}\""
62
+
63
+ #=========================================================================================
64
+ # Checks if an output directory was given. If given and directory does not exist,
65
+ # create the directory. If no directory given, pass NULL to the render function.
66
+ #=========================================================================================
67
+
68
+ if (!options[:output_dir].nil?)
69
+ Dir.mkdir(options[:output_dir]) if !Dir.exist?(options[:output_dir])
70
+ options[:output_dir] = "\"#{options[:output_dir]}\""
71
+ else
72
+ # If not, pass NULL to the render function
73
+ options[:output_dir] = "NULL"
74
+ end
75
+
76
+ #=========================================================================================
77
+ # Checks if any intermediate directory given. If not, pass NULL to the render function
78
+ # Calling render with options intermediates_dir is not working, requires further study
79
+ #=========================================================================================
80
+
81
+ if (!options[:intermediates_dir].nil?)
82
+ if !Dir.exist?(options[:intermediates_dir])
83
+ Dir.mkdir(options[:intermediates_dir])
84
+ options[:intermediates_dir] = "\"#{options[:intermediates_dir]}\""
85
+ else
86
+ options[:intermediates_dir] = "\"#{options[:intermediates_dir]}\""
87
+ end
88
+ else
89
+ options[:intermediates_dir] = "NULL"
90
+ end
91
+
92
+ options[:clean] = (options[:clean].nil?)? "TRUE" : "FALSE"
93
+
94
+ #=========================================================================================
95
+ # Sends message to user that the gKniting process has started
96
+ #=========================================================================================
97
+ puts "================================"
98
+ puts "gKnitting #{options[:input_file]} with the following options:"
99
+ puts " * Output format: \t #{options[:output_format]}"
100
+ puts " * Output file: \t #{options[:output_file]}"
101
+ puts " * Output directory: \t #{options[:output_dir]}"
102
+ puts " * Clean: \t\t #{options[:clean]}"
103
+
104
+
105
+ # Code to be evaluated by the R script
106
+ code = <<EOF
107
+ eval.polyglot("ruby", "$LOAD_PATH.unshift %q(/home/rbotafogo/desenv/galaaz/lib)")
108
+ eval.polyglot("ruby", "require %q(gknit)")
109
+
110
+ rmarkdown::render("#{options[:input_file]}", output_format = #{options[:output_format]},
111
+ output_file = #{options[:output_file]},
112
+ output_dir = #{options[:output_dir]},
113
+ clean = #{options[:clean]})
114
+ EOF
115
+
116
+
117
+ exec "Rscript --jvm --polyglot -e '#{code}'"
118
+
119
+ =begin
120
+ # how to call rmarkdown::render with a parameter list
121
+ # all params need to be defined in the YAML header
122
+ rmarkdown::render("#{options[:input_file]}", output_format = #{options[:output_format]},
123
+ output_file = #{options[:output_file]},
124
+ output_dir = #{options[:output_dir]},
125
+ clean = #{options[:clean]},
126
+ params = list(rake_clean = TRUE))
127
+ =end