Skip to contents

Generates the code for loading a dataset and returns both the code and the contents

Usage

UD_ds_read(
  state,
  data_file_ext = NULL,
  data_file_local = NULL,
  data_file = NULL,
  sheets = NULL,
  sheet = NULL
)

Arguments

state

UD state from UD_fetch_state()

data_file_ext

File extension of the uploaded file (e.g. "xlsx", "csv", etc).

data_file_local

Full path to the data file on the server.

data_file

Dataset file name without the path.

sheets

If the uploaded file is an excel file, this is a character vector of the sheets present in that file.

sheet

If the uploaded file is an excel file, this is the currently selected sheet.

Value

list with the elements of the dataset (contents, object_name, code, and isgood)

Examples

# We need a module state object to use this function:
id="UD"
sess_res = UD_test_mksession(session=list())
#> → 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
state = sess_res$state

# This is the full path to a test data file:
data_file_local  =  system.file(package="formods", "test_data", "TEST_DATA.xlsx")

# Excel file extension
data_file_ext    = "xlsx"

# Base file name
data_file        = "TEST_DATA.xlsx"

# Excel files need a sheet specification:
sheet            = "DATA"

# We will also attach the sheets along with it
sheets = readxl::excel_sheets(data_file_local)

ds_read_res = UD_ds_read(state,
  data_file_ext   = data_file_ext,
  data_file_local = data_file_local,
  data_file       = data_file,
  sheets          = sheets,
  sheet          = sheet)

ds_read_res
#> $contents
#> # A tibble: 10,680 × 33
#>       ID TIME_DY TIME_HR NTIME_DY NTIME_HR  TIME     AMT    DV RECDESC     DOSE
#>    <dbl>   <dbl>   <dbl>    <dbl>    <dbl> <dbl>   <dbl> <dbl> <chr>      <dbl>
#>  1     1       0       0        0        0     0 3000000    0  dose     3000000
#>  2     1       0       0        0        0     0       0 1250  BM_ng_ml 3000000
#>  3     1       0       0        0        0     0       0    0  C_ng_ml  3000000
#>  4     1       1      24        1       24    24       0 1647  BM_ng_ml 3000000
#>  5     1       1      24        1       24    24       0  690. C_ng_ml  3000000
#>  6     1       2      48        2       48    48       0 1947  BM_ng_ml 3000000
#>  7     1       2      48        2       48    48       0  588. C_ng_ml  3000000
#>  8     1       3      72        3       72    72       0 2170  BM_ng_ml 3000000
#>  9     1       3      72        3       72    72       0  506. C_ng_ml  3000000
#> 10     1       4      96        4       96    96       0 2332  BM_ng_ml 3000000
#> # ℹ 10,670 more rows
#> # ℹ 23 more variables: DOSE_STR <chr>, Cohort <chr>, ROUTE <chr>, WT <dbl>,
#> #   SUBTYPE <chr>, SEX <chr>, F1 <dbl>, ka <dbl>, CL <dbl>, Vc <dbl>, Vp <dbl>,
#> #   Q <dbl>, BM_IC <dbl>, kdeg_BM <dbl>, Emax <dbl>, EC50 <dbl>, CMT <chr>,
#> #   DUR <dbl>, EVID <dbl>, NDose <chr>, DOSE_NUM <dbl>, SUBTYPE_ID <dbl>,
#> #   SEX_ID <dbl>
#> 
#> $object_name
#> [1] "myDS"
#> 
#> $isgood
#> [1] TRUE
#> 
#> $code
#> [1] "myDS = readxl::read_excel(path=\"TEST_DATA.xlsx\", sheet=\"DATA\")\nmyDS = janitor::clean_names(myDS, case=\"none\")"
#>