pryr: Tools for Computing on the Language

> library(pryr)

バージョン: 0.1.2


.
%<a-% Create an active binding.
%<c-% Create a constant (locked) binding.
%<d-% Create an delayed binding.
bytes Print the byte-wise representation of a value
call_tree Display a call (or expression) as a tree.
compose Compose multiple functions
dots Capture unevaluated dots.
enclosing_env Find the environment that encloses of a
function.
explicit Tools for making promises explicit
f A compact syntax for anonymous functions.
fget Find a function with specified name.
find_funs Find functions matching criteria.
find_uses Find all functions in that call supplied
functions.
ftype Determine function type.
is_active_binding Active binding info
is_promise Promise info
make_call Make and evaluate calls.
make_function Make a function from its components.
mem_change Determine change in memory from running code
mem_used How much memory is currently used by R?
method_from_call Given a function class, find correspoding S4
method
modify_call Modify the arguments of a call.
modify_lang Recursively modify a language object
object_size Compute the size of an object.
otype Determine object type.
parent_promise Find the parent (first) promise.
parenv Get parent/ancestor environment
parenvs Given an environment or object, return an
'envlist' of its parent environments.
partial Partial apply a function, filling in some
arguments.
rebind Rebind an existing name.
rls Recursive ls.
sexp_type Inspect internal attributes of R objects.
show_c_source Find C source code for internal R functions
standardise_call Standardise a function call
subs A version of substitute that works in the
global environment.
substitute_q A version of substitute that evaluates its
first argument.
track_copy Track if an object is copied
unenclose Unenclose a closure.
uneval Capture the call associated with a promise.
where Find where a name is defined.
関数名 概略
%<a-% Create an active binding.
%<c-% Create a constant (locked) binding.
%<d-% Create an delayed binding.
bytes Print the byte-wise representation of a value
call_tree Display a call (or expression) as a tree.
compose Compose multiple functions
dots Capture unevaluated dots.
enclosing_env Find the environment that encloses of a function.
explicit Tools for making promises explicit
f A compact syntax for anonymous functions.
fget Find a function with specified name.
find_funs Find functions matching criteria.
find_uses Find all functions in that call supplied functions.
ftype Determine function type.
is_active_binding Active binding info
is_promise Promise info
make_call Make and evaluate calls.
make_function Make a function from its components.
mem_change Determine change in memory from running code
mem_used How much memory is currently used by R?
method_from_call Given a function class, find correspoding S4 method
modify_call Modify the arguments of a call.
modify_lang Recursively modify a language object
object_size Compute the size of an object.
otype Determine object type.
parent_promise Find the parent (first) promise.
parenv Get parent/ancestor environment
parenvs Given an environment or object, return an 'envlist' of its parent environments.
partial Partial apply a function, filling in some arguments.
rebind Rebind an existing name.
rls Recursive ls.
sexp_type Inspect internal attributes of R objects.
show_c_source Find C source code for internal R functions
standardise_call Standardise a function call
subs A version of substitute that works in the global environment.
substitute_q A version of substitute that evaluates its first argument.
track_copy Track if an object is copied
unenclose Unenclose a closure.
uneval Capture the call associated with a promise.
where Find where a name is defined.

bytes

> x <- y <- z <- "\u9b3c"
> Encoding(y) <- "bytes"
> Encoding(z) <- "latin1"
> print(x); print(y); print(z)
[1] "鬼"
[1] "\\xe9\\xac\\xbc"
[1] "鬼"
> bytes(x); bytes(y); bytes(z)
[1] "E9 AC BC"
[1] "E9 AC BC"
[1] "E9 AC BC"
> bits(x); bits(y); bits(z)
[1] "11101001 10101100 10111100"
[1] "11101001 10101100 10111100"
[1] "11101001 10101100 10111100"

make_function

関数の定義を行う

Arguments

  • args
  • body
  • env
> g <- make_function(alist(x = ), quote(x + 3))
> g(x = 1)
[1] 4

mem_used

メモリー使用量

> mem_used()
314 MB

otype

オブジェクトの型を定義する

> otype(data.frame())
[1] "S3"
> otype(1:10)
[1] "base"
> otype(mean)
[1] "base"
> otype("ggplot2")
[1] "base"

is_promise

> x <- 10
> is_promise(x)
[1] FALSE

parenv

環境のスコープ

Arguments

  • env
  • n
> parenv()
<environment: 0x1528c8d80>

parenvs

> parenvs(all = TRUE)
    label                                  name                     
1   <environment: 0x11e6d1870>             ""                       
2   <environment: 0x1528c8d80>             ""                       
3   <environment: namespace:Rgitbook>      ""                       
4   <environment: 0x10fea6a30>             "imports:Rgitbook"       
5   <environment: namespace:base>          ""                       
6   <environment: R_GlobalEnv>             ""                       
7   <environment: package:tidyjson>        "package:tidyjson"       
8   <environment: package:stringi>         "package:stringi"        
9   <environment: package:RJSONIO>         "package:RJSONIO"        
10  <environment: package:random>          "package:random"         
11  <environment: package:purrr>           "package:purrr"          
12  <environment: package:plan>            "package:plan"           
13  <environment: package:rpart>           "package:rpart"          
14  <environment: package:boot>            "package:boot"           
15  <environment: package:foreign>         "package:foreign"        
16  <environment: package:lattice>         "package:lattice"        
17  <environment: package:pacman>          "package:pacman"         
18  <environment: package:mime>            "package:mime"           
19  <environment: package:jsonlite>        "package:jsonlite"       
20  <environment: package:githug>          "package:githug"         
21  <environment: package:feather>         "package:feather"        
22  <environment: package:dpmr>            "package:dpmr"           
23  <environment: package:digest>          "package:digest"         
24  <environment: package:data.table>      "package:data.table"     
25  <environment: package:chunked>         "package:chunked"        
26  <environment: package:rgeos>           "package:rgeos"          
27  <environment: package:lawn>            "package:lawn"           
28  <environment: package:geosphere>       "package:geosphere"      
29  <environment: package:rstanarm>        "package:rstanarm"       
30  <environment: package:R6>              "package:R6"             
31  <environment: package:pryr>            "package:pryr"           
32  <environment: package:profvis>         "package:profvis"        
33  <environment: package:covr>            "package:covr"           
34  <environment: package:xts>             "package:xts"            
35  <environment: package:zoo>             "package:zoo"            
36  <environment: package:timeSeries>      "package:timeSeries"     
37  <environment: package:timeDate>        "package:timeDate"       
38  <environment: package:RNeo4j>          "package:RNeo4j"         
39  <environment: package:RGA>             "package:RGA"            
40  <environment: package:mice>            "package:mice"           
41  <environment: package:Rcpp>            "package:Rcpp"           
42  <environment: package:downscale>       "package:downscale"      
43  <environment: package:dismo>           "package:dismo"          
44  <environment: package:raster>          "package:raster"         
45  <environment: package:celestial>       "package:celestial"      
46  <environment: package:RANN>            "package:RANN"           
47  <environment: package:tidyr>           "package:tidyr"          
48  <environment: package:fuzzyjoin>       "package:fuzzyjoin"      
49  <environment: package:readr>           "package:readr"          
50  <environment: package:dplyr>           "package:dplyr"          
51  <environment: package:V8>              "package:V8"             
52  <environment: package:shinygadgets>    "package:shinygadgets"   
53  <environment: package:XML2R>           "package:XML2R"          
54  <environment: package:XML>             "package:XML"            
55  <environment: package:trelloR>         "package:trelloR"        
56  <environment: package:tableHTML>       "package:tableHTML"      
57  <environment: package:rvest>           "package:rvest"          
58  <environment: package:xml2>            "package:xml2"           
59  <environment: package:selectr>         "package:selectr"        
60  <environment: package:htmltidy>        "package:htmltidy"       
61  <environment: package:tutorial>        "package:tutorial"       
62  <environment: package:tidyxl>          "package:tidyxl"         
63  <environment: package:pbapply>         "package:pbapply"        
64  <environment: package:ndjson>          "package:ndjson"         
65  <environment: package:gsubfn>          "package:gsubfn"         
66  <environment: package:proto>           "package:proto"          
67  <environment: package:formatR>         "package:formatR"        
68  <environment: package:forcats>         "package:forcats"        
69  <environment: package:diffobj>         "package:diffobj"        
70  <environment: package:assertthat>      "package:assertthat"     
71  <environment: package:assertive>       "package:assertive"      
72  <environment: package:spex>            "package:spex"           
73  <environment: package:postGIStools>    "package:postGIStools"   
74  <environment: package:geographr>       "package:geographr"      
75  <environment: package:png>             "package:png"            
76  <environment: package:sp>              "package:sp"             
77  <environment: package:mapproj>         "package:mapproj"        
78  <environment: package:maps>            "package:maps"           
79  <environment: package:timevis>         "package:timevis"        
80  <environment: package:minimap>         "package:minimap"        
81  <environment: package:magick>          "package:magick"         
82  <environment: package:ggRandomForests> "package:ggRandomForests"
83  <environment: package:randomForestSRC> "package:randomForestSRC"
84  <environment: package:ggalluvial>      "package:ggalluvial"     
85  <environment: package:ensurer>         "package:ensurer"        
86  <environment: package:testwhat>        "package:testwhat"       
87  <environment: package:checkr>          "package:checkr"         
88  <environment: package:colormap>        "package:colormap"       
89  <environment: package:hms>             "package:hms"            
90  <environment: package:anytime>         "package:anytime"        
91  <environment: package:dummies>         "package:dummies"        
92  <environment: package:survey>          "package:survey"         
93  <environment: package:survival>        "package:survival"       
94  <environment: package:Matrix>          "package:Matrix"         
95  <environment: package:grid>            "package:grid"           
96  <environment: package:janitor>         "package:janitor"        
97  <environment: package:shinyLP>         "package:shinyLP"        
98  <environment: package:miniUI>          "package:miniUI"         
99  <environment: package:Rgitbook>        "package:Rgitbook"       
100 <environment: 0x10a0fe878>             "tools:rstudio"          
101 <environment: package:stats>           "package:stats"          
102 <environment: package:graphics>        "package:graphics"       
103 <environment: package:grDevices>       "package:grDevices"      
104 <environment: package:utils>           "package:utils"          
105 <environment: package:datasets>        "package:datasets"       
106 <environment: package:roracle>         "package:roracle"        
107 <environment: package:testthat>        "package:testthat"       
108 <environment: package:devtools>        "package:devtools"       
109 <environment: package:remoji>          "package:remoji"         
110 <environment: package:git2r>           "package:git2r"          
111 <environment: package:ggplot2>         "package:ggplot2"        
112 <environment: package:magrittr>        "package:magrittr"       
113 <environment: package:knitr>           "package:knitr"          
114 <environment: 0x1031fe6b0>             "JapanEnv"               
115 <environment: package:methods>         "package:methods"        
116 <environment: 0x103975b50>             "Autoloads"              
117 <environment: base>                    ""                       
118 <environment: R_EmptyEnv>              ""

track_copy

> a <- 1:5
> track_a <- track_copy(a)
> track_a()

rebind

永続代入

> a <- 1
> rebind("a", 2)
> a
[1] 2

rls

Arguments

  • env... 検索を行う環境
  • all.names... すべてのオブジェクトを表示するか(隠しオブジェクトを含めるか)
> rls()
[[1]]
 [1] "a"                "atlas.data"       "batting_tbl"     
 [4] "board"            "by_cyl"           "cc"              
 [7] "compare"          "contacts"         "ct"              
[10] "d"                "d1"               "d2"              
[13] "data"             "data.file"        "df"              
[16] "DF.dummy"         "e"                "examples"        
[19] "exdoc"            "f"                "f1"              
[22] "f2"               "fit"              "fs"              
[25] "fun1"             "fun2"             "g"               
[28] "ga_meta"          "hui"              "imp"             
[31] "Lines"            "messy"            "models"          
[34] "my_add"           "obs"              "occupancy"       
[37] "opb"              "opts"             "p"               
[40] "pat"              "plays_by_year"    "pts"             
[43] "r"                "r1"               "r2"              
[46] "res"              "s1"               "s2"              
[49] "states"           "sub_misspellings" "svgdoc"          
[52] "test"             "testit"           "thresh"          
[55] "track_a"          "train"            "txt"             
[58] "words"            "x"                "X"               
[61] "xts.ts"           "xy"               "y"               
[64] "Y"                "y1"               "y2"              
[67] "z"                "zoo.ts"          

[[2]]
 [1] "..."               "bib"               "bibs"             
 [4] "clean"             "dir"               "existing"         
 [7] "finfo"             "j"                 "knitenv"          
[10] "last.R.version"    "last.run"          "log.dir"          
[13] "log.ext"           "newfiles"          "oldwd"            
[16] "referenceFiles"    "referenceFilesPos" "rmdinfo"          
[19] "rmds"              "statusfile"

uneval

> uneval

where

Arguments

  • name
  • env
> x <- 1
> where("x")
<environment: 0x11e6d1870>
> where("t.test")
<environment: package:stats>
attr(,"name")
[1] "package:stats"
attr(,"path")
[1] "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/stats"
> where("mean")
<environment: namespace:base>
> where("where")
<environment: package:pryr>
attr(,"name")
[1] "package:pryr"
attr(,"path")
[1] "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/pryr"