rinruby 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,7 +59,7 @@
59
59
 
60
60
  class RinRuby
61
61
 
62
- VERSION = '1.0.0'
62
+ VERSION = '1.0.1'
63
63
 
64
64
  require 'socket'
65
65
 
@@ -573,13 +573,7 @@ class RinRuby
573
573
  def find_R_on_windows(cygwin)
574
574
  path = '?'
575
575
  for root in [ 'HKEY_LOCAL_MACHINE', 'HKEY_CURRENT_USER' ]
576
- version = '?'
577
- `reg query "#{root}\\Software\\R-core\\R" /v "Current Version"`.split("\n").each do |line|
578
- next if line !~ /^\s+Current Version\s+REG_SZ\s+(\d\.\d\.\d).*/
579
- version = $1
580
- break
581
- end
582
- `reg query "#{root}\\Software\\R-core\\R\\#{version}" /v "InstallPath"`.split("\n").each do |line|
576
+ `reg query "#{root}\\Software\\R-core\\R" /v "InstallPath"`.split("\n").each do |line|
583
577
  next if line !~ /^\s+InstallPath\s+REG_SZ\s+(.*)/
584
578
  path = $1
585
579
  while path.chomp!
@@ -0,0 +1,74 @@
1
+ require 'rinruby'
2
+
3
+ class Animation < RinRuby
4
+
5
+ Graphics_Drivers = ['pdf','swf']
6
+
7
+ def loop(n)
8
+ (1..n).each do |i|
9
+ print "#{100*i/n}% "
10
+ eval yield(i)
11
+ end
12
+ puts
13
+ end
14
+
15
+ def graphics(filename=nil)
16
+ if ! filename
17
+ eval "dev.off()",false
18
+ if @graphics_driver == 'swf'
19
+ system <<-EOF
20
+ pdf2swf -bl -o #{@filename}.swf #{@filename}.pdf > /dev/null 2>&1
21
+ swfdump --html #{@filename}.swf > #{@filename}.html
22
+ rm #{@filename}.pdf
23
+ EOF
24
+ end
25
+ else
26
+ graphics if pull("length(dev.list())") > 0
27
+ begin
28
+ @graphics_driver = filename[(filename.rindex('.')+1)..-1].downcase
29
+ rescue
30
+ raise "File extension must be in [ #{Graphics_Drivers.join(', ')} ]"
31
+ end
32
+ if ! Graphics_Drivers.include?(@graphics_driver)
33
+ raise "File extension must be in [ #{Graphics_Drivers.join(', ')} ]"
34
+ end
35
+ @filename = filename[0...filename.rindex('.')]
36
+ if @graphics_driver == 'pdf'
37
+ eval "pdf(paste('#{@filename}.pdf'))"
38
+ elsif @graphics_driver == 'swf'
39
+ eval "pdf(paste('#{@filename}.pdf'))"
40
+ end
41
+ end
42
+ end
43
+
44
+ def quit
45
+ graphics if pull("length(dev.list())") > 0
46
+ end
47
+
48
+ end
49
+
50
+ if $0 == __FILE__
51
+
52
+ A = Animation.new
53
+
54
+ A.graphics "example1.swf"
55
+ n = 40
56
+ A.eval "x <- rnorm(#{n})"
57
+ A.loop(n) do |i|
58
+ "plot(x[1:#{i}],xlim=c(1,#{n}),ylim=max(abs(x))*c(-1,1),type='l',ylab='')"
59
+ end
60
+
61
+ A.graphics "example2.pdf"
62
+ A.eval <<-EOF
63
+ plot(1,type="n",axes=FALSE,xlab="",ylab="")
64
+ text(1,1,"Thanks!")
65
+ EOF
66
+ A.eval <<-EOF
67
+ plot(1,type="n",axes=FALSE,xlab="",ylab="")
68
+ text(1,1,"Thanks a lot!")
69
+ EOF
70
+
71
+ A.quit
72
+
73
+ end
74
+
@@ -0,0 +1,70 @@
1
+ require 'rinruby'
2
+
3
+ class GIF
4
+
5
+ def initialize(r_interpreter,filename)
6
+ @r = r_interpreter
7
+ @filename = filename
8
+ @frame_counter = 0
9
+ end
10
+
11
+ def self.draw(r_interpreter,filename,delay)
12
+ echo = r_interpreter.echo
13
+ r_interpreter.echo false
14
+ animated = self.new(r_interpreter,filename)
15
+ yield(animated)
16
+ animated.close(delay)
17
+ r_interpreter.echo echo
18
+ end
19
+
20
+ def add(statement)
21
+ @frame_counter += 1
22
+ filename = name(@frame_counter)
23
+ @r.eval <<-EOF
24
+ png(paste('#{filename}.png'))
25
+ #{statement}
26
+ dev.off()
27
+ EOF
28
+ system "convert #{filename}.png #{filename}.gif"
29
+ File.delete "#{filename}.png"
30
+ end
31
+
32
+ def loop(n)
33
+ (1..n).each do |i|
34
+ puts "#{100*i/n}%"
35
+ add(yield(i))
36
+ end
37
+ end
38
+
39
+ def close(delay)
40
+ system "gifsicle -O2 --delay #{delay} #{@filename}-*.gif > #{@filename}.gif"
41
+ if @frame_counter > 0
42
+ (1..@frame_counter).each { |i| File.delete("#{name(i)}.gif") }
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def name(index)
49
+ sprintf("%s-%016x",@filename,index)
50
+ end
51
+
52
+ end
53
+
54
+ if $0 == __FILE__
55
+
56
+ n = 40
57
+ R.eval "x <- rnorm(#{n})"
58
+
59
+ GIF.draw(R,'time-series',5) do |a|
60
+ a.loop(n) do |i|
61
+ "plot(x[1:#{i}],xlim=c(1,#{n}),ylim=max(abs(x))*c(-1,1),type='l',ylab='')"
62
+ end
63
+ a.add <<-EOF
64
+ plot(1,type="n",axes=FALSE,xlab="",ylab="")
65
+ text(1,1,"Thanks!")
66
+ EOF
67
+ end
68
+
69
+ end
70
+
metadata CHANGED
@@ -1,47 +1,50 @@
1
- --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
3
- specification_version: 1
4
- name: rinruby
5
- version: !ruby/object:Gem::Version
6
- version: 1.0.0
7
- date: 2008-07-03 00:00:00 -05:00
8
- summary: Accessing the R interpreter from pure Ruby
9
- require_paths:
10
- - lib
1
+ --- !ruby/object:Gem::Specification
2
+ required_ruby_version: !ruby/object:Gem::Requirement
3
+ requirements:
4
+ - - '>='
5
+ - !ruby/object:Gem::Version
6
+ version: !str 0
7
+ version:
11
8
  email: rinruby@ddahl.org
9
+ cert_chain: []
10
+ summary: Accessing the R interpreter from pure Ruby
11
+ post_install_message:
12
+ extra_rdoc_files: []
12
13
  homepage: http://rinruby.ddahl.org
14
+ signing_key:
15
+ name: rinruby
16
+ rdoc_options: []
17
+ autorequire:
13
18
  rubyforge_project: rinruby
19
+ executables: []
14
20
  description:
15
- autorequire:
21
+ specification_version: 2
16
22
  default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
25
- platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
- authors:
30
- - David B. Dahl
31
23
  files:
24
+ - lib/rinruby
32
25
  - lib/rinruby.rb
26
+ - lib/rinruby/gif.rb
27
+ - lib/rinruby/animation.rb
33
28
  - README.txt
34
- test_files: []
35
-
36
- rdoc_options: []
37
-
38
- extra_rdoc_files: []
39
-
40
- executables: []
41
-
29
+ required_rubygems_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: !str 0
34
+ version:
42
35
  extensions: []
43
-
36
+ rubygems_version: 1.2.0
44
37
  requirements:
45
38
  - R (http://www.r-project.org), an environment for statistical computing and graphics
39
+ authors:
40
+ - David B. Dahl
41
+ date: 2008-08-20 05:00:00 +00:00
42
+ platform: ruby
43
+ test_files: []
44
+ version: !ruby/object:Gem::Version
45
+ version: 1.0.1
46
+ require_paths:
47
+ - lib
46
48
  dependencies: []
47
-
49
+ bindir: bin
50
+ has_rdoc: true