f_read_any_json: Read a '.json' File in the '.pbix' Collection of Files

Description Usage Arguments Value Author(s) See Also Examples

View source: R/f_read_any_json.R

Description

The byte sequence of a '.json' file within a '.pbix' is retrieved, cleaned by removing ASCII control characters and written to a temporary file. An attempt is made to read the temporary file as '.json'. If reading the temporary file as '.json' fails, a second attempt is made. For the second attempt, specific data within the '.json' file is included and a temporary file is written. The temporary file is read as '.json'.

Usage

1
f_read_any_json(input_file_pbix, input_file, gsub1, gsub2)

Arguments

input_file_pbix

Path of the input '.pbix'.

input_file

Path of '.json' file in collection of files.

gsub1

Text to select for replacement (i.e. text to exclude).

gsub2

Text to replace selected text (i.e. text to include).

Value

Layout as '.json'.

Author(s)

Don Diproto

See Also

Uses: f_get_pbix_fir.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## Not run: 
# Get dummy data ------------------------------------------------------------
# Create a temporary directory
temp_dir <- file.path(tempdir(),"functionTest")
if(!dir.exists(temp_dir)) {
	dir.create(temp_dir)
}
sample_file_name <- "OR_sample_func.pbix"
pathFileSample <- file.path(temp_dir, sample_file_name)

# See if dummy data already exists in temporary directory
parent_temp_dir <- dirname(temp_dir)
existing_file <- list.files(parent_temp_dir,
pattern = sample_file_name, recursive = TRUE, full.names = TRUE)

# Download the sample .pbix if it doesn't exist
if (length(existing_file) == 0) {
   url_pt1 <- "https://github.com/KoenVerbeeck/PowerBI-Course/blob/"
   url_pt2 <- "master/pbix/TopMovies.pbix?raw=true"
   url <- paste0(url_pt1, url_pt2)
   req <- download.file(url, destfile = pathFileSample, mode = "wb")
} else {
   pathFileSample <- existing_file[1]
}
# Do stuff ------------------------------------------------------------------

# Run the function
gsub__1 <- paste0(".*sections")
gsub__2 <- "{\"id\":0,\"sections"
test <- f_read_any_json(pathFileSample, "Report/Layout",
                        gsub__1, gsub__2)
  
## End(Not run)

pbixr documentation built on Oct. 27, 2020, 5:07 p.m.