|
4 | 4 | #' described `resources`. |
5 | 5 | #' |
6 | 6 | #' @inheritParams read_resource |
7 | | -#' @return List describing a Data Resource, with new property `read_from` to |
8 | | -#' indicate how data should be read. |
| 7 | +#' @return List describing a Data Resource, with new attribute `data_location` |
| 8 | +#' to indicate how the data are attached. |
9 | 9 | #' If present, `path` will be updated to contain the full path(s). |
10 | 10 | #' @family accessor functions |
11 | 11 | #' @noRd |
@@ -47,25 +47,26 @@ resource <- function(package, resource_name) { |
47 | 47 | ) |
48 | 48 | } |
49 | 49 |
|
50 | | - # Assign read_from property (based on path, then df, then data) |
| 50 | + # Add data_location attribute (based on path, then df, then data) |
51 | 51 | if (length(resource$path) != 0) { |
52 | 52 | if (all(is_url(resource$path))) { |
53 | | - resource$read_from <- "url" |
| 53 | + data_location <- "url" |
54 | 54 | } else { |
55 | | - resource$read_from <- "path" |
| 55 | + data_location <- "path" |
56 | 56 | } |
57 | 57 | # Expand paths to full paths, check if file exists and check path safety, |
58 | 58 | # unless those paths were willingly added by user in add_resource() |
59 | 59 | if (attr(resource, "path") %||% "" != "added") { |
60 | 60 | resource$path <- purrr::map_chr( |
61 | | - resource$path, ~ check_path(.x, package$directory, safe = TRUE) |
| 61 | + resource$path, ~ check_path(.x, attr(package, "directory"), safe = TRUE) |
62 | 62 | ) |
63 | 63 | } |
64 | 64 | } else if (is.data.frame(resource$data)) { |
65 | | - resource$read_from <- "df" |
| 65 | + data_location <- "df" |
66 | 66 | } else if (!is.null(resource$data)) { |
67 | | - resource$read_from <- "data" |
| 67 | + data_location <- "data" |
68 | 68 | } |
| 69 | + attr(resource, "data_location") <- data_location |
69 | 70 |
|
70 | 71 | return(resource) |
71 | 72 | } |
0 commit comments