-
Notifications
You must be signed in to change notification settings - Fork 2
Document guess tspec #296
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
Merged
Merged
Document guess tspec #296
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
28a9b5d
docs: document spec guessing
jonthegeek 34227fc
Merged origin/main into fix-249-document-guess_tspec
jonthegeek 12d3844
Continuing after merge from main.
jonthegeek 7eee302
Merge branch 'main' into fix-249-document-guess_tspec
jonthegeek 2f5b3c2
Merge branch 'main' into fix-249-document-guess_tspec
jonthegeek 6c3ad91
Refactor for maintainability
jonthegeek b0c9896
Merge branch 'main' into fix-249-document-guess_tspec
jonthegeek 7ad7cf2
Apply suggestions from copilot code review.
jonthegeek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #' Guess the `tibblify()` specification | ||
| #' | ||
| #' @description | ||
| #' | ||
| #' `guess_tspec()` automatically dispatches to the other `guess_tspec_*()` | ||
| #' functions based on the shape of the input. If you are unhappy with its | ||
| #' output, calling a specific `guess_tspec_*()` function may yield better | ||
| #' results, or at least clearer error messages about why that type isn't | ||
| #' supported. | ||
| #' | ||
| #' - Use `guess_tspec_df()` if the input is a data frame. | ||
| #' - Use `guess_tspec_object()` if the input is an object (such as a JSON | ||
| #' object that has been read into R as a named list). | ||
| #' - Use `guess_tspec_object_list()` if the input is a list of objects (such as | ||
| #' a JSON object that has been read into R as a list of named lists). | ||
| #' - Use `guess_tspec_list()` if the input object is a list but you aren't sure | ||
| #' how it should be processed. | ||
| #' | ||
| #' See `vignette("supported-structures")` for a discussion of the input types | ||
| #' supported by tibblify. | ||
| #' | ||
| #' @param x (`list` or `data.frame`) A nested list or a data frame. | ||
| #' @param ... These dots are for future extensions and must be empty. | ||
| #' @inheritParams .shared-params | ||
| #' | ||
| #' @returns A specification object that can be used in [tibblify()]. | ||
| #' @export | ||
| #' | ||
| #' @examples | ||
| #' guess_tspec(list(x = 1, y = "a")) | ||
| #' guess_tspec(list(list(x = 1), list(x = 2))) | ||
| #' | ||
| #' guess_tspec(gh_users) | ||
| guess_tspec <- function( | ||
| x, | ||
| ..., | ||
| empty_list_unspecified = FALSE, | ||
| simplify_list = FALSE, | ||
| inform_unspecified = should_inform_unspecified(), | ||
| call = rlang::caller_env() | ||
| ) { | ||
| rlang::check_dots_empty(call = call) | ||
| if (is.data.frame(x)) { | ||
| return(guess_tspec_df( | ||
| x, | ||
| empty_list_unspecified = empty_list_unspecified, | ||
| simplify_list = simplify_list, | ||
| inform_unspecified = inform_unspecified, | ||
| call = call | ||
| )) | ||
| } | ||
| if (vctrs::obj_is_list(x)) { | ||
| return(guess_tspec_list( | ||
| x, | ||
| empty_list_unspecified = empty_list_unspecified, | ||
| simplify_list = simplify_list, | ||
| inform_unspecified = inform_unspecified, | ||
| call = call | ||
| )) | ||
| } | ||
| stop_input_type( | ||
| x, | ||
| c("a data frame", "a list"), | ||
| arg = caller_arg(x), | ||
| call = call | ||
| ) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.