alex_r 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ require 'rubygems'
1
2
  require 'alex_r'
2
3
 
3
- AlexR.execute("panel_of_pictures.pdf", "panel_of_pictures.r")
4
+ output = File.expand_path(File.join(File.dirname(__FILE__), "panel_of_pictures.pdf"))
5
+ r_script = File.expand_path(File.join(File.dirname(__FILE__), "panel_of_pictures.r"))
6
+ AlexR.execute(output, r_script)
@@ -1,7 +1,31 @@
1
+ require 'rubygems'
1
2
  require 'alex_r'
2
3
 
3
- AlexR.execute("panel_of_pictures.pdf") do |r|
4
- File.open("panel_of_pictures.r") do |file|
5
- r << file.readlines.join("\n")
6
- end
4
+ output = File.expand_path(File.join(File.dirname(__FILE__), "panel_of_pictures.pdf"))
5
+ r_script = %[
6
+ par(mfrow=c(3,2))
7
+
8
+ plot(density(runif(100)), lwd=2)
9
+ text(x=0, y=0.2, "100 uniforms")
10
+ abline(h=0, v=0)
11
+
12
+ x=seq(0.01,1,0.01)
13
+ par(col="blue")
14
+
15
+ plot(x, sin(x), type="l")
16
+ lines(x, cos(x), type="l", col="red")
17
+
18
+ plot(x, exp(x), type="l", col="green")
19
+ lines(x, log(x), type="l", col="orange")
20
+
21
+ plot(x, tan(x), type="l", lwd=3, col="yellow")
22
+
23
+ plot(x, exp(-x), lwd=2)
24
+ lines(x, exp(x), col="green", lwd=3)
25
+
26
+ plot(x, sin(x*x), type="l")
27
+ lines(x, sin(1/x), col="pink")
28
+ ]
29
+ AlexR.execute(output) do |r|
30
+ r << r_script
7
31
  end
data/lib/alex_r.rb CHANGED
@@ -2,7 +2,10 @@ require 'open3'
2
2
 
3
3
  class AlexR
4
4
  def self.execute(output_file, input_file_path=nil)
5
- stdin, stdout, stderr = Open3.popen3('Rscript -')
5
+ r_executable = "Rscript -"
6
+ r_executable = r_executable.insert(0, "cd #{File.dirname(input_file_path)} && ") if input_file_path
7
+
8
+ stdin, stdout, stderr = Open3.popen3(r_executable)
6
9
  stdin << "pdf('#{output_file}')\n"
7
10
  if input_file_path
8
11
  File.open(input_file_path) do |file|
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alex_r
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 27
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 1
9
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
10
11
  platform: ruby
11
12
  authors:
12
13
  - Jae Lee
@@ -45,6 +46,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
45
46
  requirements:
46
47
  - - ">="
47
48
  - !ruby/object:Gem::Version
49
+ hash: 3
48
50
  segments:
49
51
  - 0
50
52
  version: "0"
@@ -53,13 +55,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
55
  requirements:
54
56
  - - ">="
55
57
  - !ruby/object:Gem::Version
58
+ hash: 3
56
59
  segments:
57
60
  - 0
58
61
  version: "0"
59
62
  requirements: []
60
63
 
61
64
  rubyforge_project:
62
- rubygems_version: 1.3.7
65
+ rubygems_version: 1.4.2
63
66
  signing_key:
64
67
  specification_version: 3
65
68
  summary: alex_r is a thin wrapper around RScript