Skip to contents

Resources such as datasets can be specified using the module ID and either identifier index or the resource label. This function will attempt to rectify those and give the "best" answer. If a resource label is supplied and exists uniquely for that module ID, that object will be returned. If not then an error will be returned. If the resource label is not specified and the index is specified and that exists uniquely, that object will be returned. Otherwise an error will be returned.

Usage

fetch_resource(catalog = NULL, id = NULL, idx = NULL, res_label = NULL)

Arguments

catalog

Catalog table returned from formods fetch functions (e.g. 'FM_fetch_ds()).

id

Module id.

idx

Element id from module, can be set to NULL or "" if the res_label option is set.

res_label

Resource label, must be set to NULL or "" to ignore the resource label and use idx.

Value

list containing the current dataset with the following format:

  • isgood: Boolean indicating the whether a resource object was found.

  • msgs: Any messages generated

  • res_row: Row of catalog associated with resource or NULL if not found.

  • res_obj: Name of resource object or NULL if not found.

Examples

# We need a module state and a Shiny session variable
# to use this function:
sess_res = UD_test_mksession()
#> → ASM: including file
#> → ASM:   source: file.path(system.file(package="onbrand"), "templates", "report.docx")
#> → ASM:   dest:   file.path("config","report.docx")
#> → ASM: including file
#> → ASM:   source: file.path(system.file(package="onbrand"), "templates", "report.pptx")
#> → ASM:   dest:   file.path("config","report.pptx")
#> → ASM: including file
#> → ASM:   source: file.path(system.file(package="onbrand"), "templates", "report.yaml")
#> → ASM:   dest:   file.path("config","report.yaml")
#> → ASM: State initialized
#> → ASM: setting word placeholders: 
#> → ASM:   -> setting docx ph: HEADERLEFT = left header
#> → ASM:   -> setting docx ph: HEADERRIGHT = right header
#> → ASM:   -> setting docx ph: FOOTERLEFT = left footer
#> → ASM: module isgood: TRUE
#> → UD: including file
#> → UD:   source: file.path(system.file(package="onbrand"), "templates", "report.docx")
#> → UD:   dest:   file.path("config","report.docx")
#> → UD: including file
#> → UD:   source: file.path(system.file(package="onbrand"), "templates", "report.pptx")
#> → UD:   dest:   file.path("config","report.pptx")
#> → UD: including file
#> → UD:   source: file.path(system.file(package="onbrand"), "templates", "report.yaml")
#> → UD:   dest:   file.path("config","report.yaml")
#> → UD: State initialized
#> → UD: module checksum updated:897d952fecbc804999396a96f9df4b20
#> → UD: module isgood: TRUE
#> → # preload_complete is good: TRUE ------------------------------------------
session = sess_res$session
state   = sess_res$state

DSV = FM_fetch_ds(state=state, session=session, ids=c("UD", "DM", "DW"), meta_only=TRUE)

fetch_resource(catalog=DSV[["catalog"]], id = "UD", idx="1", res_label = "")
#> $isgood
#> [1] TRUE
#> 
#> $msgs
#> [1] "found by idx"
#> 
#> $res_row
#>               label object MOD_TYPE      MOD_DESC id idx res_label
#> 1 Original data set   myDS       UD Uploaded Data UD   1          
#>                           checksum                       DSchecksum
#> 1 897d952fecbc804999396a96f9df4b20 897d952fecbc804999396a96f9df4b20
#>                                                                                                      code
#> 1 myDS = rio::import(file="TEST_DATA.xlsx", which="DATA")\nmyDS = janitor::clean_names(myDS, case="none")
#> 
#> $res_obj
#> [1] "myDS"
#>