Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Allow reader to pull data from a URL #8

Closed
mstackhouse opened this issue Sep 13, 2023 · 3 comments
Closed

Feature Request: Allow reader to pull data from a URL #8

mstackhouse opened this issue Sep 13, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@mstackhouse
Copy link
Contributor

Feature Idea

Replicate the function of haven, where haven::read_xpt() can pull directly from a URL like GitHub raw files

Relevant Input

URL

Relevant Output

Dataframe

Reproducible Example/Pseudo Code

datasetjson::read_dataset_json(https://raw.githubusercontent.com/cdisc-org/DataExchange-DatasetJson/master/examples/sdtm/dm.json)
@mstackhouse mstackhouse added the enhancement New feature or request label Sep 13, 2023
@mstackhouse
Copy link
Contributor Author

con <- url(
  "https://github.com/cdisc-org/DataExchange-DatasetJson/raw/master/examples/sdtm/ti.json", 
  method = "libcurl"
  )

x <- readLines(con, warn=FALSE)

close(con)

jsonlite::fromJSON(x)

@mstackhouse
Copy link
Contributor Author

For a local file for testing:

con <- url(paste0("file://", normalizePath(test_path("testdata", "ta.json"))))

@mstackhouse
Copy link
Contributor Author

This is url detection from {readr}:

https://github.com/tidyverse/readr/blob/b3d09122074143987754a83ccb6eec730a20a37e/R/source.R#L196

is_url <- function(path) {
  grepl("^((http|ftp)s?|sftp)://", path)
}

Could just add in additionally for local files:

^((http|ftp)s?|sftp|file):\/\/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant