-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from mlverse/updates
Cleans up functions
- Loading branch information
Showing
20 changed files
with
478 additions
and
336 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: lang | ||
Title: Using an Large Language Model of your choice, it translates the R | ||
help documentation to a specific language | ||
Version: 0.0.0.9001 | ||
Version: 0.0.0.9002 | ||
Authors@R: | ||
person("Edgar", "Ruiz", , "[email protected]", role = c("aut", "cre")) | ||
Description: Use an 'LLM' to translate a function's help documentation on-the-fly. | ||
|
This file contains 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 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,37 @@ | ||
#' Convert to and from ISO 639 language code | ||
#' | ||
#' @param lang Name of the language to be converted | ||
#' @param silent Flag to indicate if the function should return a message | ||
#' with the result. If there is no match, it will be an error message | ||
#' @export | ||
to_iso639 <- function(lang, silent = TRUE) { | ||
codes <- readRDS(system.file("iso/codes.rds", package = "lang")) | ||
lang <- tolower(lang) | ||
match <- codes[codes$name == lang, "code"] | ||
if (nrow(match) > 0) { | ||
out <- as.character(match)[[1]] | ||
if (!silent) { | ||
cli_alert_success("'{lang}' converted to ISO 639 code: '{out}'") | ||
} | ||
} else { | ||
if (!silent) { | ||
cli_abort("'{lang}' could not be matched to an ISO 639 code") | ||
} | ||
out <- NULL | ||
} | ||
out | ||
} | ||
|
||
#' @rdname to_iso639 | ||
#' @param iso The two-letter ISO 639 code to search | ||
from_iso639 <- function(iso) { | ||
codes <- readRDS(system.file("iso/codes.rds", package = "lang")) | ||
iso <- tolower(iso) | ||
match <- codes[codes$code == iso, ] | ||
if (nrow(match) > 0) { | ||
out <- match$name | ||
} else { | ||
out <- NULL | ||
} | ||
out | ||
} |
This file contains 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 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 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,24 @@ | ||
roxy_comments <- function(x) { | ||
script_contents <- readLines(x) | ||
roxy_comment <- substr(script_contents, 1, 2) == "#'" | ||
just_roxy <- script_contents[roxy_comment] | ||
just_roxy <- just_roxy[just_roxy != "#'"] | ||
|
||
if (length(just_roxy) == 0) { | ||
return(NULL) | ||
} else { | ||
just_roxy <- paste0("#-", just_roxy) | ||
no_exports <- !any(grepl("#' @export", just_roxy)) | ||
no_name <- !any(grepl("#' @name", just_roxy)) | ||
if (no_exports && no_name) { | ||
return(NULL) | ||
} | ||
} | ||
just_roxy | ||
} | ||
|
||
roxy_existing <- function(x) { | ||
script_contents <- readLines(x) | ||
roxy_comment <- substr(script_contents, 1, 4) == "#-#'" | ||
script_contents[roxy_comment] | ||
} |
Oops, something went wrong.