Fetch all data in the table by the given name, returning a tibble with field names corresponding to the columns in that table.
fetch_table(api, table_id, filters = NULL)
A 'gristapi::grist_api'-object
Normalized table name (see id
in listtables
method). First character upper. OBLIGATORY
String. This is a JSON object mapping column names AND (&) sorting result AND (&) limit number of rows.
example : filter={"Country":["UNITED STATES"],"Card_Member":["CLARE DUDLEY","DARIUS BURGESS"]}&sort=Card_Member,-Date&limit=10
See the grist API doc for more examples
Note : add &hidden=true
to include the hidden columns
Default NULL
A tibble::tibble()
object.
Other function_gristapi:
add_records()
,
countrows()
,
delete_records()
,
listcolumns()
,
listtables()
,
sync_table()
,
update_records()
# view all data from a given table
table_name <- paste0("Mtcars_", get_os())
api <- grist_api$new(
server = 'https://grist.numerique.gouv.fr',
api_key = Sys.getenv("GRIST_KEY"),
doc_id = Sys.getenv("GRIST_DOC_TEST")
)
fetch_table(api, table_name)
#> # A tibble: 32 × 13
#> id names mpg cyl disp hp drat wt qsec vs am gear carb
#> <int> <chr> <dbl> <int> <dbl> <int> <dbl> <dbl> <dbl> <int> <int> <int> <int>
#> 1 1 Mazd… 21 6 160 110 3.9 2.62 16.5 0 1 4 4
#> 2 2 Mazd… 21 6 160 110 3.9 2.88 17.0 0 1 4 4
#> 3 3 Dats… 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
#> 4 4 Horn… 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1
#> 5 5 Horn… 18.7 8 360 175 3.15 3.44 17.0 0 0 3 2
#> 6 7 Dust… 14.3 8 360 245 3.21 3.57 15.8 0 0 3 4
#> 7 8 Merc… 24.4 4 147. 62 3.69 3.19 20 1 0 4 2
#> 8 9 Merc… 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2
#> 9 10 Merc… 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4
#> 10 11 Merc… 17.8 6 168. 123 3.92 3.44 18.9 1 0 4 4
#> # ℹ 22 more rows
# view data from a given table with a limit
fetch_table(api, table_name, filters = "limit=10")
#> # A tibble: 10 × 13
#> id names mpg cyl disp hp drat wt qsec vs am gear carb
#> <int> <chr> <dbl> <int> <dbl> <int> <dbl> <dbl> <dbl> <int> <int> <int> <int>
#> 1 1 Mazd… 21 6 160 110 3.9 2.62 16.5 0 1 4 4
#> 2 2 Mazd… 21 6 160 110 3.9 2.88 17.0 0 1 4 4
#> 3 3 Dats… 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
#> 4 4 Horn… 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1
#> 5 5 Horn… 18.7 8 360 175 3.15 3.44 17.0 0 0 3 2
#> 6 7 Dust… 14.3 8 360 245 3.21 3.57 15.8 0 0 3 4
#> 7 8 Merc… 24.4 4 147. 62 3.69 3.19 20 1 0 4 2
#> 8 9 Merc… 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2
#> 9 10 Merc… 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4
#> 10 11 Merc… 17.8 6 168. 123 3.92 3.44 18.9 1 0 4 4
# view data from a given table with a filter
fetch_table(api, table_name, filters = 'filter={"cyl": [8]}')
#> # A tibble: 15 × 13
#> id names mpg cyl disp hp drat wt qsec vs am gear carb
#> <int> <chr> <dbl> <int> <dbl> <int> <dbl> <dbl> <dbl> <int> <int> <int> <int>
#> 1 5 Horn… 18.7 8 360 175 3.15 3.44 17.0 0 0 3 2
#> 2 7 Dust… 14.3 8 360 245 3.21 3.57 15.8 0 0 3 4
#> 3 12 Merc… 16.4 8 276. 180 3.07 4.07 17.4 0 0 3 3
#> 4 13 Merc… 17.3 8 276. 180 3.07 3.73 17.6 0 0 3 3
#> 5 14 Merc… 15.2 8 276. 180 3.07 3.78 18 0 0 3 3
#> 6 15 Cadi… 10.4 8 472 205 2.93 5.25 18.0 0 0 3 4
#> 7 16 Linc… 10.4 8 460 215 3 5.42 17.8 0 0 3 4
#> 8 17 Chry… 14.7 8 440 230 3.23 5.34 17.4 0 0 3 4
#> 9 22 Dodg… 15.5 8 318 150 2.76 3.52 16.9 0 0 3 2
#> 10 23 AMC … 15.2 8 304 150 3.15 3.44 17.3 0 0 3 2
#> 11 24 Cama… 13.3 8 350 245 3.73 3.84 15.4 0 0 3 4
#> 12 25 Pont… 19.2 8 400 175 3.08 3.84 17.0 0 0 3 2
#> 13 29 Ford… 15.8 8 351 264 4.22 3.17 14.5 0 1 5 4
#> 14 31 Mase… 15 8 301 335 3.54 3.57 14.6 0 1 5 8
#> 15 33 Dust… 16.7 8 360 245 3.21 3.57 15.8 0 0 3 4