Skip to content

Instantly share code, notes, and snippets.

@foloinfo
Created November 19, 2013 05:40
Show Gist options
  • Save foloinfo/7540812 to your computer and use it in GitHub Desktop.
Save foloinfo/7540812 to your computer and use it in GitHub Desktop.
Rからerb記述が含まれるyamlを読み込む ref: http://qiita.com/foloinfo/items/9ce4662953f9ace094e1
> system('ruby -e "puts 1+1"', intern=TRUE)
[1] "2"
> system("ruby script.rb", intern=T)
require 'erb'
p ERB.new(File.read('database.yml')).result
yaml.load(yaml.load(system("ruby load_erb.rb", intern=T)))
$test
$test$adapter
[1] "sqlite3"
$test$database
[1] "db/test.sqlite3"
$test$pool
[1] 5
$test$timeout
[1] 5000
eq <- "ruby -e 'require \"erb\"; p ERB.new(File.read(\"database.yml\")).result'"
yaml.load(yaml.load(system(eq, intern=T)))
yaml.load_erb <- function(path){
eq <- paste("ruby -e 'require \"erb\"; p ERB.new(File.read(\"", path,"\")).result'", collapse='', sep='')
yaml.load(yaml.load(system(eq, intern=T)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment