pysty is a Python style packages importing using the common forms
of: import PACKAGE
, import PACKAGE as ALIAS
, or
from PACKAGE import FUN1, FUN2, FUN_N
. The latter even allows for
importing non-exported functions into the global environment.
This package is a proof of concept that such light weight importing and aliasing could be possible. A user would use pysty because one wants to be explicit in all the functions used in a script as to what package they come from. Aliasing package names is convenient for longer named packages.
To download the development version of pysty:
Download the zip ball
or tar ball,
decompress and run R CMD INSTALL
on it, or use the pacman package
to install the development version:
if (!require("pacman")) install.packages("pacman")
pacman::p_load_gh("trinker/pysty")
You are welcome to: - submit suggestions and bug-reports at: https://github.com/trinker/pysty/issues - send a pull request on: https://github.com/trinker/pysty/ - compose a friendly e-mail to: tyler.rinker@gmail.com
There are only a few functions in the package:
Function Descriptionadd_imports
Python style importing
clear_imports
Remove a named import(s) or all imports
get_imports
See imported packages
get_imports_functions
See imported functions
library(pysty)
add_imports('
import dplyr as dp
import ggplot2 as gg
import tidyr
from plyr import l_ply, rbind.fill
')
l_ply
## function (.data, .fun = NULL, ..., .progress = "none", .inform = FALSE,
## .print = FALSE, .parallel = FALSE, .paropts = NULL)
## {
## if (is.character(.fun) || is.list(.fun))
## .fun <- each(.fun)
## if (!is.function(.fun))
## stop(".fun is not a function.")
## pieces <- as.list(.data)
## n <- length(pieces)
## if (n == 0)
## return(invisible())
## if (.parallel && .progress != "none") {
## message("Progress disabled when using parallel plyr")
## .progress <- "none"
## }
## progress <- create_progress_bar(.progress)
## progress$init(n)
## on.exit(progress$term())
## if (.parallel && .print) {
## message("Printing disabled for parallel processing")
## .print <- FALSE
## }
## do.ply <- function(i) {
## piece <- pieces[[i]]
## if (.inform) {
## res <- try(.fun(piece, ...))
## if (inherits(res, "try-error")) {
## piece <- paste(utils::capture.output(print(piece)),
## collapse = "\n")
## stop("with piece ", i, ": \n", piece, call. = FALSE)
## }
## }
## else {
## res <- .fun(piece, ...)
## }
## if (.print) {
## print(res)
## }
## progress$step()
## }
## if (.parallel) {
## setup_parallel()
## .paropts$.combine <- function(...) NULL
## i <- seq_len(n)
## fe_call <- as.call(c(list(quote(foreach::foreach), i = i),
## .paropts))
## fe <- eval(fe_call)
## foreach::`%dopar%`(fe, do.ply(i))
## }
## else {
## for (i in seq_len(n)) {
## do.ply(i)
## }
## }
## invisible()
## }
## <environment: namespace:plyr>
dp::arrange
## function (.data, ...)
## {
## arrange_(.data, .dots = lazyeval::lazy_dots(...))
## }
## <environment: namespace:dplyr>
dp:::wrap
## function (..., indent = 0)
## {
## x <- paste0(..., collapse = "")
## wrapped <- strwrap(x, indent = indent, exdent = indent +
## 2, width = getOption("width"))
## paste0(wrapped, collapse = "\n")
## }
## <environment: namespace:dplyr>
ls()
## [1] "desc" "l_ply" "loc" "rbind.fill" "regex"
## [6] "ver" "verbadge"
get_imports()
## package alias
## 1 dplyr dp
## 2 ggplot2 gg
## 3 tidyr tidyr
get_imports_functions()
## package alias
## 1 plyr rbind.fill
## 2 plyr l_ply
clear_imports()
l_ply
dp::arrange
dp:::wrap
ls()
get_imports()
get_imports_functions()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.