Skip to content

Commit 9d84925

Browse files
authored
Cache datasets (#282)
1 parent 4ca32c7 commit 9d84925

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/utilities.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,21 @@ function replicate(f::Function, n::Integer; use_threads=false)
116116
results
117117
end
118118

119+
cacheddatasets = Dict{String,Any}()
119120
"""
120121
dataset(nm)
121122
122123
Return the data frame of test data set named `nm`, which can be a `String` or `Symbol`
123124
"""
124125
function dataset(nm::AbstractString)
125-
path = joinpath(TestData, nm * ".feather")
126-
if !isfile(path)
127-
throw(ArgumentError(
128-
"Dataset \"$nm\" is not available.\nUse MixedModels.datasets() for available names."))
126+
get!(cacheddatasets, nm) do
127+
path = joinpath(TestData, nm * ".feather")
128+
if !isfile(path)
129+
throw(ArgumentError(
130+
"Dataset \"$nm\" is not available.\nUse MixedModels.datasets() for available names."))
131+
end
132+
Feather.read(path)
129133
end
130-
Feather.read(path)
131134
end
132135
dataset(nm::Symbol) = dataset(string(nm))
133136

0 commit comments

Comments
 (0)