An open API service indexing awesome lists of open source software.

https://github.com/moodymudskipper/pkg

Package Objects
https://github.com/moodymudskipper/pkg

Last synced: 3 months ago
JSON representation

Package Objects

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# pkg

pkgs and repos as R6 objects

## examples

```{r}
library(pkg)

# create a new package, by default a temp dir is associated to it
# with `p <- Package$new(".")` you'll be working in your working directory and it
# would fetch the package info from there
p <- Package$new()

# A print method summarizes the object
p

# we can edit the description
p$DESCRIPTION$set(Package = "math", Title = "Basic math")
p

# We can add functions using this idiom and create a function in its own script
# no `p$add` element is actually created! instead `p$R$add.R` is created and populated
p$add <- function(x, y) {x + y}
p$R$add.R

# This script might be edited interactively
# p$R$add.R$edit()

# we can add to the script with this idiom
# here again `p$R$add.R$subtract` is not created, but `p$R$add.R` is updated
p$R$add.R$subtract <- function(x, y) {x - y}
p$R$add.R$foo <- letters # we're not limited to functions
p$R$add.R

# if the script doesn't already exist it's created
p$R$other.R$multiply <- function(x, y) {x * y}
p$R$other.R

# I can load the package already and use it as I would with devtools::load_all()
p$load()
add(1, 2)

# the associated folder is not always in sync but now it is since we needed to dump to load
list.files(p$path, recursive = T)

# We can dump manually as well
p$dump()

# we also have repo objects, with methods that are essentially wrappers around {gert}
glue_repo <- Repo$new("https://github.com/tidyverse/glue")
glue_repo

glue_repo$tag$list() |> head(3)

# we can pick a version and convert it to a package object
glue_1.1.0 <- glue_repo$tag$as_pkg("v1.1.0")

glue_1.1.0

# we can load it and use it as if it was installed
glue_1.1.0$load(export_all = FALSE, quiet = TRUE)
glue("{letters[1:3]}!")

# both packages are there
search()
```