alex_r 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/alex_r.rb +18 -14
  2. metadata +21 -6
@@ -1,25 +1,29 @@
1
- require 'open3'
1
+ require 'open4'
2
2
 
3
3
  class AlexR
4
4
  def self.execute(output_file, input_file_path=nil)
5
5
  r_executable = "Rscript -"
6
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)
9
- stdin << "pdf('#{output_file}')\n"
10
- if input_file_path
11
- File.open(input_file_path) do |file|
12
- until file.eof?
13
- stdin << "#{file.readline}\n"
7
+
8
+ r_output = ""
9
+ r_error = ""
10
+ status = Open4::popen4(r_executable) do |pid, stdin, stdout, stderr|
11
+ stdin << "pdf('#{output_file}')\n"
12
+ if input_file_path
13
+ File.open(input_file_path) do |file|
14
+ until file.eof?
15
+ stdin << "#{file.readline}\n"
16
+ end
14
17
  end
18
+ else
19
+ yield(stdin) if block_given?
15
20
  end
16
- else
17
- yield(stdin) if block_given?
21
+ stdin.close
22
+ r_output = stdout.read
23
+ r_error = stderr.read
18
24
  end
19
- stdin.close
20
25
 
21
- errors = stderr.readlines
22
- raise errors.join("\n") unless errors.empty?
23
- return stdout.readlines.join("\n")
26
+ raise r_error unless status.success?
27
+ r_output
24
28
  end
25
29
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alex_r
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jae Lee
@@ -15,10 +15,25 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-09 00:00:00 +00:00
18
+ date: 2011-02-10 00:00:00 +00:00
19
19
  default_executable:
20
- dependencies: []
21
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: open4
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 21
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 1
34
+ version: 1.0.1
35
+ type: :runtime
36
+ version_requirements: *id001
22
37
  description: Allows you execute RScript
23
38
  email: jlee@yetitrails.com
24
39
  executables: []