rdatasets 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d83d00803d71e447c6d4ec666cc256619d406341aabdecf8e32d141c65ee42b7
4
- data.tar.gz: 4829511ff20f1dc8482f517ee0e49cadbe7c70d85b1f08198561dd6aee630492
3
+ metadata.gz: 4885051665cb07837095ed6c509b1fb6b701fc5646060c4002fd21e21bd82ad5
4
+ data.tar.gz: ea511278964d6fe0f460cce77f226d1f6dcab72e8ffde816e4651d3513e66498
5
5
  SHA512:
6
- metadata.gz: eea59ee442f3d3a26188942fa8b7689600152dfe8fda583720afc3dfd139f3d9d306ae4c246d3c685ed01d7c3b9d39f025a8ad2a802da5bce290e5e804ef7904
7
- data.tar.gz: 46ff298cbce5e13b90b9fbb0c97346de5368a0b8abc819e0341642e06296e109ebd941309f5c46851d5b04fa113cf17436ad523199eb6fe7c3d607697fc5ce85
6
+ metadata.gz: 0507f82fbf2eb9cd86b59489ddf3ce8bd63163bbcf13b0979c78f8f3c5f3c4776a2c7a2ae52b2d7106aa92f736092a1435db5b28f5d70037e60ebe2652c68509
7
+ data.tar.gz: fdea2c475cede1d2718978611cd84b5966659351a806a0d83047c83b6e1b7fe9fbc269b4fe752f5936271d69092a0509e071fb2712befdfc3657f25e4879a422
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rdatasets (0.3.2)
4
+ rdatasets (0.4.0)
5
5
  daru
6
6
 
7
7
  GEM
@@ -14,6 +14,9 @@ GEM
14
14
  diff-lcs (1.3)
15
15
  packable (1.3.10)
16
16
  backports
17
+ parallel (1.13.0)
18
+ parallel_tests (2.27.1)
19
+ parallel
17
20
  rake (10.5.0)
18
21
  rspec (3.8.0)
19
22
  rspec-core (~> 3.8.0)
@@ -35,6 +38,7 @@ PLATFORMS
35
38
 
36
39
  DEPENDENCIES
37
40
  bundler (~> 2.0)
41
+ parallel_tests
38
42
  rake (~> 10.0)
39
43
  rdatasets!
40
44
  rspec (~> 3.0)
File without changes
data/README.md CHANGED
@@ -8,6 +8,8 @@ This ruby gem allows you to access over 1200 datasets included in R from Ruby.
8
8
  - All the datasets were ported from [RDatasets](https://github.com/vincentarelbundock/Rdatasets) created by Vincent.
9
9
  - This Ruby gem was inspired by [RDatasets.jl](https://github.com/johnmyleswhite/RDatasets.jl) created by John Myles White.
10
10
 
11
+ under development
12
+
11
13
  ## Installation
12
14
 
13
15
  ```bash
@@ -9,9 +9,15 @@ module RDatasets
9
9
  # @param package_name [String, Symbol] :R package name
10
10
  # @param dataset_name [String, Symbol] :R dataset name
11
11
  # @return [Daru::DataFrame]
12
- def load(package_name, dataset_name)
13
- file_path = filepath(package_name, dataset_name)
14
- Daru::DataFrame.from_csv(file_path)
12
+ def load(package_name, dataset_name = nil)
13
+ if dataset_name
14
+ file_path = filepath(package_name, dataset_name)
15
+ df = Daru::DataFrame.from_csv(file_path)
16
+ df.set_index(df[0].name) if original_index_is_sequential? df
17
+ df
18
+ else
19
+ packages(package_name)
20
+ end
15
21
  end
16
22
 
17
23
  # Get the file path of a certain dataset.
@@ -26,14 +32,40 @@ module RDatasets
26
32
  # "car" package directory is a symbolic link.
27
33
  # Do not use Symbolic links because they can cause error on Windows.
28
34
  package_name = 'carData' if package_name == 'car'
29
- dataset_name << '.csv'
35
+ dataset_name += '.csv'
30
36
  File.join(rdata_directory, package_name, dataset_name)
31
37
  end
32
38
 
33
- def packages
39
+ # Display information of all data sets.
40
+ # @return [Daru::DataFrame]
41
+ def datasets
34
42
  file_path = File.expand_path('../data/datasets.csv', __dir__)
35
43
  Daru::DataFrame.from_csv(file_path)
36
44
  end
45
+
46
+ #
47
+ # @overload packages
48
+ # Show a list of all packages.
49
+ # @return [Array<Symbol>]
50
+ # @overload packages(package_name)
51
+ # Show a list of datasets included in the package.
52
+ # @param [String, Symbol] :R package name
53
+ # @return [Array<Symbol>]
54
+ def packages(package_name = nil)
55
+ if package_name
56
+ df = datasets
57
+ ds = df.where(df['Package'].eq package_name.to_s)
58
+ ds['Item'].to_a.map(&:to_sym)
59
+ else
60
+ datasets['Package'].to_a.uniq.map(&:to_sym)
61
+ end
62
+ end
63
+
64
+ # Check if the index of original r dataset is sequential.
65
+ def original_index_is_sequential?(df)
66
+ df[0].to_a == [1..df.size]
67
+ end
68
+ private_class_method :original_index_is_sequential?
37
69
  end
38
70
 
39
71
  module Daru
@@ -1,3 +1,3 @@
1
1
  module RDatasets
2
- VERSION = '0.3.2'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency 'daru'
26
26
 
27
27
  spec.add_development_dependency 'bundler', '~> 2.0'
28
+ spec.add_development_dependency 'parallel_tests'
28
29
  spec.add_development_dependency 'rake', '~> 10.0'
29
30
  spec.add_development_dependency 'rspec', '~> 3.0'
30
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdatasets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-17 00:00:00.000000000 Z
11
+ date: 2019-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: daru
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: parallel_tests
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -76,9 +90,9 @@ files:
76
90
  - ".gitignore"
77
91
  - ".rspec"
78
92
  - ".travis.yml"
79
- - GPL-3
80
93
  - Gemfile
81
94
  - Gemfile.lock
95
+ - LICENSE.md
82
96
  - README.md
83
97
  - Rakefile
84
98
  - data/COUNT/affairs.csv
@@ -1350,8 +1364,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1350
1364
  - !ruby/object:Gem::Version
1351
1365
  version: '0'
1352
1366
  requirements: []
1353
- rubyforge_project:
1354
- rubygems_version: 2.7.6
1367
+ rubygems_version: 3.0.1
1355
1368
  signing_key:
1356
1369
  specification_version: 4
1357
1370
  summary: Ruby package for loading classical data sets vailable in R