pryr provides tools to pry back the covers of R and understand the language at a deeper level. It has been developed in conjunction with "Advanced R programming" to make it easier to understand what's going on in R.
Questions tagged [pryr]
26 questions
11
votes
1 answer
What is a parent promise?
In package pryr, there is a function called parent_promise.
I know what a promise is, but I'm not familiar with the term parent promise. Furthermore, I don't really understand the example in the documentation, perhaps because I don't know what…

Rich Scriven
- 97,041
- 11
- 181
- 245
10
votes
6 answers
Converting positional arguments to named parameters in an R function based on variable name
In R there's common function calling pattern that looks like this:
child = function(a, b, c) {
a * b - c
}
parent = function(a, b, c) {
result = child(a=a, b=b, c=c)
}
This repetition of names is helpful because it prevents potentially…

Nathan Kurz
- 1,649
- 1
- 14
- 28
9
votes
1 answer
Why is the address of a loop variable changing when using it?
Program 1:
library(pryr)
for (x in 1:3) {
print(c(address(x), refs(x)))
}
Output e.g.:
[1] "0x7a6a6c8" "1"
[1] "0x7a6a6c8" "1"
[1] "0x7a6a6c8" "1"
Program 2:
library(pryr)
for (x in 1:3) {
print(c(address(x),…

Wipster
- 1,510
- 1
- 15
- 32
7
votes
1 answer
Bind data.frames row-wise in R without creating copies
I have a large list of data.frames that need to be bound pairwise by columns and then by rows prior to being fed into a predictive model. As no values will be modified, I would like to have the final data.frame pointing to the original data.frames…

alexvpickering
- 632
- 1
- 8
- 20
6
votes
0 answers
Size of nested vs. unested (tidy) data.frame?
This question uses a data.frame which contains list-columns (nested). It had me wondering why/if there's an advantage to working this way. I assumed you would want to minimize the amount of memory each table uses...But when I checked I was…

npjc
- 4,134
- 1
- 22
- 34
5
votes
1 answer
saving a base r plot as an object that can be plotted in a multiplot
This question builds from a related post which shows how to easily store a plot as an r object with the %

B. Davis
- 3,391
- 5
- 42
- 78
5
votes
1 answer
R address function
I am using the address() function in the pryr package in R, and was wondering if this following result is to be expected...
x <- 1:10
add <- function(obj){address(obj)}
address(x)
# [1] "0x112d007b0"
add(x)
# [1] "0x11505c580"
i.e. 0x112d007b0 !=…

h.l.m
- 13,015
- 22
- 82
- 169
5
votes
3 answers
Function generation; change defaults of other functions (partial)
I have the need for a function generator that takes another function and any arguments of that function and sets new defaults. I thought @hadley's pryr::partial was that magic function. It does exactly what I want except you can't then change that…

Tyler Rinker
- 108,132
- 65
- 322
- 519
4
votes
3 answers
How can I get the values of all arguments used when evaluating a call object in a specified environment
say I have a function f as
f = function(x = 1, y, z, t) { x + y + z}
and a list l such
l = list(Y = 2, t = "test")
I can evaluate f in l like
eval(quote(f(y = Y, z = 3)), envir = l)
6
My question is that I'd like to get all the values of the…

statquant
- 13,672
- 21
- 91
- 162
3
votes
2 answers
Conversion of pryr::mem_used() among memory units (MB, GB, ...)
pryr::mem_used() shows memory use as megabytes by default. Why does it convert the unit name (e.g. MB ->GB) after multiplication (or division) but not the value?
library(pryr)
mem_used()
97.1 MB
mem_used()/1000
97 kB
mem_used()*1000
97…

Tomiris
- 69
- 5
3
votes
1 answer
get the name of variable returned by R function
I have this code:
library(magrittr)
a <- function(cars) return(cars)
b <- function(x) return(list(varname = deparse(substitute(x)), content = x))
b(cars) returns a list with the string cars and the content of the data.frame cars.
Any way to get…

user3874377
- 255
- 3
- 10
2
votes
2 answers
How can I get the function object from a call object
I am trying to retrieve a function object from a call object
In this example
ff = function(x) {gg(x)}
gg = function(y) {uu(y)}
uu = function(z) {browser()}
ff(1)
Say I want to get the function ff from…

statquant
- 13,672
- 21
- 91
- 162
2
votes
0 answers
Is 'show_c_source()' broken?
Been trying to use show_c_source() from Hadley Wickhams pryr package, and every time I get the following error message:
Error in file(con, "r") : cannot open the connection
Even the examples provided in the function documentation do not work:
>…

Glen Moutrie
- 295
- 3
- 9
2
votes
0 answers
Partial application of MASS::rlm(method="MM")
I'm looking at this question in which someone is attempting to use MASS::rlm(method="MM") from within geom_smooth() in ggplot.
I thought this would be a grand opportunity for pryr::partial, but have been confused by what I think is a dispatch…

Peter
- 4,219
- 4
- 28
- 40
1
vote
0 answers
Does pryr::object_size() play poorly with nesting in tibbles and/or data frames?
When trying to run pryr::object_size() on a nested tibble or data frame, I receive the error below:
Error in obj_size_(dots, env, size_node(), size_vector()) :
bad binding access
Is this caused by having nesting in the data frames and/or…

The Count
- 183
- 10