Skip to content

Commit 907c791

Browse files
committed
Move up the config file description section.
1 parent a97c862 commit 907c791

1 file changed

Lines changed: 42 additions & 37 deletions

File tree

README.md

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,6 @@ loaded from and saved to each versioned folder.
1919
install.packages('versioning')
2020
```
2121

22-
## Quick Start
23-
24-
```r
25-
library(versioning)
26-
27-
# Load the example config bundled with the package
28-
example_config_fp <- system.file('extdata', 'example_config.yaml', package = 'versioning')
29-
config <- Config$new(config_list = example_config_fp)
30-
31-
# Print the full config
32-
print(config)
33-
34-
# Access settings (throws an error if the key doesn't exist)
35-
config$get('a') #> [1] "foo"
36-
config$get('group_c', 'd') #> [1] 1e+05
37-
38-
# Point directories at temporary folders for this example
39-
config$config_list$directories$raw_data$path <- tempdir()
40-
config$config_list$directories$prepared_data$path <- tempdir()
41-
42-
# Get directory and file paths
43-
config$get_dir_path('prepared_data') # <tempdir>/v1 (versioned)
44-
config$get_file_path('raw_data', 'a') # <tempdir>/example_input_file.csv
45-
46-
# Copy the bundled input file into the raw_data directory
47-
file.copy(
48-
from = system.file('extdata', 'example_input_file.csv', package = 'versioning'),
49-
to = config$get_file_path('raw_data', 'a')
50-
)
51-
52-
# Read and write files (format inferred from extension)
53-
df <- config$read(dir_name = 'raw_data', file_name = 'a')
54-
config$write(df, dir_name = 'prepared_data', file_name = 'prepared_table')
55-
56-
# Save the config itself to the prepared_data directory as config.yaml
57-
config$write_self(dir_name = 'prepared_data')
58-
```
5922

6023
## Config File Format
6124

@@ -101,6 +64,46 @@ Each entry in `directories` contains:
10164
When `versioned: TRUE`, `config$get_dir_path('prepared_data')` returns
10265
`~/project/prepared_data/v1` (appending the version from `versions$prepared_data`).
10366

67+
68+
## Quick Start
69+
70+
```r
71+
library(versioning)
72+
73+
# Load the example config bundled with the package
74+
example_config_fp <- system.file('extdata', 'example_config.yaml', package = 'versioning')
75+
config <- Config$new(config_list = example_config_fp)
76+
77+
# Print the full config
78+
print(config)
79+
80+
# Access settings (throws an error if the key doesn't exist)
81+
config$get('a') #> [1] "foo"
82+
config$get('group_c', 'd') #> [1] 1e+05
83+
84+
# Point directories at temporary folders for this example
85+
config$config_list$directories$raw_data$path <- tempdir()
86+
config$config_list$directories$prepared_data$path <- tempdir()
87+
88+
# Get directory and file paths
89+
config$get_dir_path('prepared_data') # <tempdir>/v1 (versioned)
90+
config$get_file_path('raw_data', 'a') # <tempdir>/example_input_file.csv
91+
92+
# Copy the bundled input file into the raw_data directory
93+
file.copy(
94+
from = system.file('extdata', 'example_input_file.csv', package = 'versioning'),
95+
to = config$get_file_path('raw_data', 'a')
96+
)
97+
98+
# Read and write files (format inferred from extension)
99+
df <- config$read(dir_name = 'raw_data', file_name = 'a')
100+
config$write(df, dir_name = 'prepared_data', file_name = 'prepared_table')
101+
102+
# Save the config itself to the prepared_data directory as config.yaml
103+
config$write_self(dir_name = 'prepared_data')
104+
```
105+
106+
104107
## Overriding Versions Programmatically
105108

106109
You can override specific versions at load time without editing the YAML file. This is
@@ -115,6 +118,7 @@ config_v2 <- Config$new(
115118
config_v2$get_dir_path('prepared_data') # ~/project/prepared_data/v2
116119
```
117120

121+
118122
## Supported File Formats
119123

120124
`config$read()` and `config$write()` dispatch on file extension via `autoread()` and
@@ -128,6 +132,7 @@ config_v2$get_dir_path('prepared_data') # ~/project/prepared_data/v2
128132
Required packages for each format are loaded on demand (e.g. **data.table** for CSV,
129133
**sf** for shapefiles, **terra** for rasters).
130134

135+
131136
## Further Reading
132137

133138
- Vignette: `vignette('versioning', package = 'versioning')`

0 commit comments

Comments
 (0)