Skip to content

Commit

Permalink
Move data utilities to separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
hsm207 committed May 17, 2020
1 parent 3693c6a commit c244912
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ using Gen, RCall, Statistics, DataFrames

import StatsBase

include("data.jl")
using .Data

export get_data,
get_posterior_samples,
get_prediction_log_probs,
Expand All @@ -17,10 +20,6 @@ export get_data,
VariableSpecification,
waic

build_url(filename) = "https://raw.githubusercontent.com/rmcelreath/rethinking/master/data/$(filename).csv"
retrieve_file(url) = HTTP.get(url).body |> IOBuffer |> CSV.read
get_data(filename) = build_url(filename) |> retrieve_file

struct VariableSpecification
lower_bound::Float64
upper_bound::Float64
Expand Down
10 changes: 10 additions & 0 deletions src/data.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Data
using HTTP, CSV

export get_data

build_url(filename) = "https://raw.githubusercontent.com/rmcelreath/rethinking/master/data/$(filename).csv"
retrieve_file(url) = HTTP.get(url).body |> IOBuffer |> CSV.read
get_data(filename) = build_url(filename) |> retrieve_file

end

0 comments on commit c244912

Please sign in to comment.