Skip to content

Commit

Permalink
feat: get urls from tableau workbook
Browse files Browse the repository at this point in the history
  • Loading branch information
tin900 committed Jan 19, 2024
1 parent 42a47ce commit 9c6a462
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export(get_variable_folders)
export(get_variables)
export(get_workbook_id)
export(get_workbook_tabs)
export(get_workbook_urls)
export(make_rootnodes)
export(query_user_on_site)
export(remove_user_from_group)
Expand Down
36 changes: 36 additions & 0 deletions R/get_workbook_urls.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#' Get Workbook URLs
#'
#' This function parses an XML document representing a Tableau workbook and finds all nodes that have a url attribute containing 'views'.
#' It then extracts these URLs and returns them in a data frame.
#'
#' @param wb The path to the Tableau workbook file (.twb).
#'
#' @return A data frame containing the URLs found in the workbook.
#' @export
get_workbook_urls <- function(wb) {
# Parse the XML document
doc <- XML::xmlParse(wb)

# Get the root node
root <- XML::xmlRoot(doc)

# Find all nodes that have a url attribute containing 'views'
nodes <- XML::xpathSApply(root, "//*[contains(@url, 'views')]")

# Initialize an empty vector to store the URLs
urls <- character(length(nodes))

# Loop over the nodes
for (i in seq_along(nodes)) {
# Extract the URL attribute
url <- XML::xmlGetAttr(nodes[[i]], "url")

# Store the URL in the urls vector
urls[i] <- url
}

# Convert the urls vector to a data frame
dfUrls <- data.frame(URL = urls)

return(dfUrls)
}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,6 @@ reference:
- get_variables
- get_workbook_id
- get_workbook_tabs
- get_workbook_urls
- make_rootnodes

18 changes: 18 additions & 0 deletions man/get_workbook_urls.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9c6a462

Please sign in to comment.