R
were not available or needed to be relearned.R
packages often provide data sets for illustration/experimentation. As a rule Julia
packages don't.RCall
package (JuliaStats/RCall.jl)¶ccall
function. Steven Johnson had written PyCall
. Avik created JavaCall
RCall
. Most of the recent work has been done by Randy Lai and Simon Byrne.reval
, rcall
, rcopy
, etc.using RCall # make the package available
whos(RCall)
@R_str 2163 bytes Function @rget 1576 bytes Function @rimport 1860 bytes Function @rlibrary 1296 bytes Function @rput 1542 bytes Function @rusing 452 bytes Function @var_str 259 bytes Function CharSxp 136 bytes DataType ClosSxp 148 bytes DataType CplxSxp 136 bytes DataType IntSxp 136 bytes DataType LglSxp 136 bytes DataType NilSxp 112 bytes DataType RCall 566 KB Module RObject 168 bytes DataType RealSxp 136 bytes DataType StrSxp 136 bytes DataType Sxp 92 bytes DataType anyNA 1377 bytes Function getAttrib 2722 bytes Function getNames 978 bytes Function globalEnv 8 bytes RCall.RObject{RCall.EnvSxp} isFactor 1066 bytes Function isNA 4223 bytes Function isOrdered 1067 bytes Function rcall 3149 bytes Function rcopy 39 KB Function reval 6289 bytes Function rlang 2229 bytes Function rparse 829 bytes Function rprint 4106 bytes Function setAttrib! 4453 bytes Function setNames! 1054 bytes Function
?rcall
search: rcall RCall remotecall remotecall_wait remotecall_fetch UniformScaling
Evaluate a function in the global environment. The first argument corresponds to the function to be called. It can be either a FunctionSxp type, a SymSxp or a Symbol.
?rcopy
search: rcopy precompile __precompile__ readchomp ProcessGroup
Evaluate and convert the result of a string as an R expression.
rcopy
copies the contents of an R object into a corresponding canonical Julia type.
rcopy(T,p)
converts a pointer p
to a Sxp object to a native Julia object of type T.
rcopy(p)
performs a default conversion.
mtcars = rcopy("mtcars")
mpg | cyl | disp | hp | drat | wt | qsec | vs | am | gear | carb | |
---|---|---|---|---|---|---|---|---|---|---|---|
1 | 21.0 | 6.0 | 160.0 | 110.0 | 3.9 | 2.62 | 16.46 | 0.0 | 1.0 | 4.0 | 4.0 |
2 | 21.0 | 6.0 | 160.0 | 110.0 | 3.9 | 2.875 | 17.02 | 0.0 | 1.0 | 4.0 | 4.0 |
3 | 22.8 | 4.0 | 108.0 | 93.0 | 3.85 | 2.32 | 18.61 | 1.0 | 1.0 | 4.0 | 1.0 |
4 | 21.4 | 6.0 | 258.0 | 110.0 | 3.08 | 3.215 | 19.44 | 1.0 | 0.0 | 3.0 | 1.0 |
5 | 18.7 | 8.0 | 360.0 | 175.0 | 3.15 | 3.44 | 17.02 | 0.0 | 0.0 | 3.0 | 2.0 |
6 | 18.1 | 6.0 | 225.0 | 105.0 | 2.76 | 3.46 | 20.22 | 1.0 | 0.0 | 3.0 | 1.0 |
7 | 14.3 | 8.0 | 360.0 | 245.0 | 3.21 | 3.57 | 15.84 | 0.0 | 0.0 | 3.0 | 4.0 |
8 | 24.4 | 4.0 | 146.7 | 62.0 | 3.69 | 3.19 | 20.0 | 1.0 | 0.0 | 4.0 | 2.0 |
9 | 22.8 | 4.0 | 140.8 | 95.0 | 3.92 | 3.15 | 22.9 | 1.0 | 0.0 | 4.0 | 2.0 |
10 | 19.2 | 6.0 | 167.6 | 123.0 | 3.92 | 3.44 | 18.3 | 1.0 | 0.0 | 4.0 | 4.0 |
11 | 17.8 | 6.0 | 167.6 | 123.0 | 3.92 | 3.44 | 18.9 | 1.0 | 0.0 | 4.0 | 4.0 |
12 | 16.4 | 8.0 | 275.8 | 180.0 | 3.07 | 4.07 | 17.4 | 0.0 | 0.0 | 3.0 | 3.0 |
13 | 17.3 | 8.0 | 275.8 | 180.0 | 3.07 | 3.73 | 17.6 | 0.0 | 0.0 | 3.0 | 3.0 |
14 | 15.2 | 8.0 | 275.8 | 180.0 | 3.07 | 3.78 | 18.0 | 0.0 | 0.0 | 3.0 | 3.0 |
15 | 10.4 | 8.0 | 472.0 | 205.0 | 2.93 | 5.25 | 17.98 | 0.0 | 0.0 | 3.0 | 4.0 |
16 | 10.4 | 8.0 | 460.0 | 215.0 | 3.0 | 5.424 | 17.82 | 0.0 | 0.0 | 3.0 | 4.0 |
17 | 14.7 | 8.0 | 440.0 | 230.0 | 3.23 | 5.345 | 17.42 | 0.0 | 0.0 | 3.0 | 4.0 |
18 | 32.4 | 4.0 | 78.7 | 66.0 | 4.08 | 2.2 | 19.47 | 1.0 | 1.0 | 4.0 | 1.0 |
19 | 30.4 | 4.0 | 75.7 | 52.0 | 4.93 | 1.615 | 18.52 | 1.0 | 1.0 | 4.0 | 2.0 |
20 | 33.9 | 4.0 | 71.1 | 65.0 | 4.22 | 1.835 | 19.9 | 1.0 | 1.0 | 4.0 | 1.0 |
21 | 21.5 | 4.0 | 120.1 | 97.0 | 3.7 | 2.465 | 20.01 | 1.0 | 0.0 | 3.0 | 1.0 |
22 | 15.5 | 8.0 | 318.0 | 150.0 | 2.76 | 3.52 | 16.87 | 0.0 | 0.0 | 3.0 | 2.0 |
23 | 15.2 | 8.0 | 304.0 | 150.0 | 3.15 | 3.435 | 17.3 | 0.0 | 0.0 | 3.0 | 2.0 |
24 | 13.3 | 8.0 | 350.0 | 245.0 | 3.73 | 3.84 | 15.41 | 0.0 | 0.0 | 3.0 | 4.0 |
25 | 19.2 | 8.0 | 400.0 | 175.0 | 3.08 | 3.845 | 17.05 | 0.0 | 0.0 | 3.0 | 2.0 |
26 | 27.3 | 4.0 | 79.0 | 66.0 | 4.08 | 1.935 | 18.9 | 1.0 | 1.0 | 4.0 | 1.0 |
27 | 26.0 | 4.0 | 120.3 | 91.0 | 4.43 | 2.14 | 16.7 | 0.0 | 1.0 | 5.0 | 2.0 |
28 | 30.4 | 4.0 | 95.1 | 113.0 | 3.77 | 1.513 | 16.9 | 1.0 | 1.0 | 5.0 | 2.0 |
29 | 15.8 | 8.0 | 351.0 | 264.0 | 4.22 | 3.17 | 14.5 | 0.0 | 1.0 | 5.0 | 4.0 |
30 | 19.7 | 6.0 | 145.0 | 175.0 | 3.62 | 2.77 | 15.5 | 0.0 | 1.0 | 5.0 | 6.0 |
⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
R"""
suppressMessages(library(lme4))
fm1 <- lmer(Yield ~ 1 + (1 | Batch), Dyestuff, REML = FALSE)
getME(fm1, "theta")
"""[1]
0.7525806925786059
using DataFrames
brownian(N) = DataFrame(x = 1:N, y = cumsum(randn(N)))
srand(1234321) # set random number seed
br = brownian(10_000);
R"""
suppressMessages(library(ggplot2))
ggplot($br, aes(x = x, y = y)) + geom_line()
"""
RCall.RObject{RCall.VecSxp}
?
for help; ;
for shell)RCall
adds an R REPL mode (magic char is $
). Cxx
adds a C++
REPL mode (magic is <
).ccall
, cglobal
, cfunction
, Libdl.dlopen
allow low-level access to a C API.@pyimport
macro functions like import
in Python.using PyCall
@pyimport numpy as np
@pyimport pandas as pd
@pyimport feather
whos(pd)
Categorical 8 bytes PyCall.PyObject CategoricalIndex 8 bytes PyCall.PyObject DataFrame 8 bytes PyCall.PyObject DateOffset 8 bytes PyCall.PyObject DatetimeIndex 8 bytes PyCall.PyObject ExcelFile 8 bytes PyCall.PyObject ExcelWriter 8 bytes PyCall.PyObject Expr 8 bytes PyCall.PyObject Float64Index 8 bytes PyCall.PyObject Grouper 8 bytes PyCall.PyObject HDFStore 8 bytes PyCall.PyObject Index 8 bytes PyCall.PyObject IndexSlice 8 bytes PyCall.PyObject Int64Index 8 bytes PyCall.PyObject MultiIndex 8 bytes PyCall.PyObject NaT 8 bytes PyCall.PyObject Panel 8 bytes PyCall.PyObject Panel4D 8 bytes PyCall.PyObject Period 8 bytes PyCall.PyObject PeriodIndex 8 bytes PyCall.PyObject RangeIndex 8 bytes PyCall.PyObject Series 8 bytes PyCall.PyObject SparseArray 8 bytes PyCall.PyObject SparseDataFrame 8 bytes PyCall.PyObject SparseList 8 bytes PyCall.PyObject SparsePanel 8 bytes PyCall.PyObject SparseSeries 8 bytes PyCall.PyObject SparseTimeSeries 8 bytes PyCall.PyObject Term 8 bytes PyCall.PyObject TimeGrouper 8 bytes PyCall.PyObject TimeSeries 8 bytes PyCall.PyObject Timedelta 8 bytes PyCall.PyObject TimedeltaIndex 8 bytes PyCall.PyObject Timestamp 8 bytes PyCall.PyObject WidePanel 8 bytes PyCall.PyObject __anon__ 10 KB Module algos 8 bytes PyCall.PyObject bdate_range 8 bytes PyCall.PyObject compat 8 bytes PyCall.PyObject computation 8 bytes PyCall.PyObject concat 8 bytes PyCall.PyObject core 8 bytes PyCall.PyObject crosstab 8 bytes PyCall.PyObject cut 8 bytes PyCall.PyObject date_range 8 bytes PyCall.PyObject datetime 8 bytes PyCall.PyObject datetools 8 bytes PyCall.PyObject dependency 16 bytes ASCIIString describe_option 8 bytes PyCall.PyObject eval 8 bytes PyCall.PyObject ewma 8 bytes PyCall.PyObject ewmcorr 8 bytes PyCall.PyObject ewmcov 8 bytes PyCall.PyObject ewmstd 8 bytes PyCall.PyObject ewmvar 8 bytes PyCall.PyObject ewmvol 8 bytes PyCall.PyObject expanding_apply 8 bytes PyCall.PyObject expanding_corr 8 bytes PyCall.PyObject expanding_count 8 bytes PyCall.PyObject expanding_cov 8 bytes PyCall.PyObject expanding_kurt 8 bytes PyCall.PyObject expanding_max 8 bytes PyCall.PyObject expanding_mean 8 bytes PyCall.PyObject expanding_median 8 bytes PyCall.PyObject expanding_min 8 bytes PyCall.PyObject expanding_quantile 8 bytes PyCall.PyObject expanding_skew 8 bytes PyCall.PyObject expanding_std 8 bytes PyCall.PyObject expanding_sum 8 bytes PyCall.PyObject expanding_var 8 bytes PyCall.PyObject factorize 8 bytes PyCall.PyObject fama_macbeth 8 bytes PyCall.PyObject formats 8 bytes PyCall.PyObject get_dummies 8 bytes PyCall.PyObject get_option 8 bytes PyCall.PyObject get_store 8 bytes PyCall.PyObject groupby 8 bytes PyCall.PyObject hard_dependencies 65 bytes Tuple{ASCIIString,ASCIIString,ASCI… hashtable 8 bytes PyCall.PyObject index 8 bytes PyCall.PyObject indexes 8 bytes PyCall.PyObject infer_freq 8 bytes PyCall.PyObject info 8 bytes PyCall.PyObject io 8 bytes PyCall.PyObject isnull 8 bytes PyCall.PyObject json 8 bytes PyCall.PyObject lib 8 bytes PyCall.PyObject lreshape 8 bytes PyCall.PyObject match 8 bytes PyCall.PyObject melt 8 bytes PyCall.PyObject merge 8 bytes PyCall.PyObject missing_dependencies 0 bytes 0-element Array{Any,1} msgpack 8 bytes PyCall.PyObject notnull 8 bytes PyCall.PyObject np 8 bytes PyCall.PyObject offsets 8 bytes PyCall.PyObject ols 8 bytes PyCall.PyObject option_context 8 bytes PyCall.PyObject options 8 bytes PyCall.PyObject ordered_merge 8 bytes PyCall.PyObject pandas 8 bytes PyCall.PyObject parser 8 bytes PyCall.PyObject period_range 8 bytes PyCall.PyObject pivot 8 bytes PyCall.PyObject pivot_table 8 bytes PyCall.PyObject plot_params 357 bytes Dict{Any,Any} with 1 entry pnow 8 bytes PyCall.PyObject qcut 8 bytes PyCall.PyObject read_clipboard 8 bytes PyCall.PyObject read_csv 8 bytes PyCall.PyObject read_excel 8 bytes PyCall.PyObject read_fwf 8 bytes PyCall.PyObject read_gbq 8 bytes PyCall.PyObject read_hdf 8 bytes PyCall.PyObject read_html 8 bytes PyCall.PyObject read_json 8 bytes PyCall.PyObject read_msgpack 8 bytes PyCall.PyObject read_pickle 8 bytes PyCall.PyObject read_sas 8 bytes PyCall.PyObject read_sql 8 bytes PyCall.PyObject read_sql_query 8 bytes PyCall.PyObject read_sql_table 8 bytes PyCall.PyObject read_stata 8 bytes PyCall.PyObject read_table 8 bytes PyCall.PyObject reset_option 8 bytes PyCall.PyObject rolling_apply 8 bytes PyCall.PyObject rolling_corr 8 bytes PyCall.PyObject rolling_count 8 bytes PyCall.PyObject rolling_cov 8 bytes PyCall.PyObject rolling_kurt 8 bytes PyCall.PyObject rolling_max 8 bytes PyCall.PyObject rolling_mean 8 bytes PyCall.PyObject rolling_median 8 bytes PyCall.PyObject rolling_min 8 bytes PyCall.PyObject rolling_quantile 8 bytes PyCall.PyObject rolling_skew 8 bytes PyCall.PyObject rolling_std 8 bytes PyCall.PyObject rolling_sum 8 bytes PyCall.PyObject rolling_var 8 bytes PyCall.PyObject rolling_window 8 bytes PyCall.PyObject scatter_matrix 8 bytes PyCall.PyObject set_eng_float_format 8 bytes PyCall.PyObject set_option 8 bytes PyCall.PyObject show_versions 8 bytes PyCall.PyObject sparse 8 bytes PyCall.PyObject stats 8 bytes PyCall.PyObject test 8 bytes PyCall.PyObject timedelta_range 8 bytes PyCall.PyObject to_datetime 8 bytes PyCall.PyObject to_msgpack 8 bytes PyCall.PyObject to_numeric 8 bytes PyCall.PyObject to_pickle 8 bytes PyCall.PyObject to_timedelta 8 bytes PyCall.PyObject tools 8 bytes PyCall.PyObject tseries 8 bytes PyCall.PyObject tslib 8 bytes PyCall.PyObject types 8 bytes PyCall.PyObject unique 8 bytes PyCall.PyObject util 8 bytes PyCall.PyObject value_counts 8 bytes PyCall.PyObject wide_to_long 8 bytes PyCall.PyObject
function brown(N::Number)
v = zeros(N + 1)
for i in 1:N
v[i + 1] = v[i] + randn()
end
v
end
brown (generic function with 1 method)
df = pd.DataFrame(Dict("br1" => pd.Series(brown(10_000)), "br2" => pd.Series(brown(10_000))))
br1 | br2 | |
---|---|---|
0 | 0.000000 | 0.000000 |
1 | -0.773834 | -0.006075 |
2 | -0.537581 | -0.281177 |
3 | 0.070239 | 0.989620 |
4 | 0.913922 | 0.272461 |
5 | 0.783253 | 0.943957 |
6 | 1.847161 | 0.796048 |
7 | 0.448132 | 1.478668 |
8 | -2.358731 | 0.106409 |
9 | -3.037559 | -0.322209 |
10 | -0.647172 | -0.024637 |
11 | -0.324446 | 0.887330 |
12 | -1.087391 | 0.764816 |
13 | -0.092598 | 1.635592 |
14 | 0.270325 | 1.103798 |
15 | 0.026771 | 0.601902 |
16 | -1.469982 | 1.815822 |
17 | -2.144328 | 0.957945 |
18 | -3.344290 | 1.105669 |
19 | -2.112758 | 1.303400 |
20 | -3.072021 | 0.911289 |
21 | -2.243848 | 1.488212 |
22 | -1.276259 | 1.990742 |
23 | -2.105055 | 2.864032 |
24 | -1.909855 | 4.591759 |
25 | -2.241574 | 4.498321 |
26 | -2.712888 | 4.342676 |
27 | -2.501568 | 4.245411 |
28 | -2.737541 | 3.471929 |
29 | -1.666890 | 3.263433 |
... | ... | ... |
9971 | -67.201469 | -37.090684 |
9972 | -68.372847 | -37.603236 |
9973 | -69.053534 | -37.842471 |
9974 | -67.648497 | -38.373551 |
9975 | -65.773006 | -39.242039 |
9976 | -66.520155 | -39.173315 |
9977 | -66.774692 | -40.773012 |
9978 | -67.839113 | -39.828624 |
9979 | -68.676012 | -40.120377 |
9980 | -68.364612 | -38.445496 |
9981 | -66.843212 | -38.913253 |
9982 | -66.390980 | -38.201632 |
9983 | -65.733951 | -37.470297 |
9984 | -65.099306 | -38.119241 |
9985 | -66.354152 | -37.442763 |
9986 | -68.651218 | -38.013503 |
9987 | -67.823224 | -37.741410 |
9988 | -68.053629 | -38.639877 |
9989 | -67.943860 | -36.262430 |
9990 | -66.721974 | -35.792575 |
9991 | -67.957720 | -35.626207 |
9992 | -68.531987 | -34.892304 |
9993 | -68.036708 | -34.475120 |
9994 | -69.109629 | -34.392904 |
9995 | -69.369302 | -34.677581 |
9996 | -69.953834 | -36.628048 |
9997 | -69.380250 | -37.220133 |
9998 | -69.382725 | -36.422765 |
9999 | -69.528264 | -35.077929 |
10000 | -68.787819 | -35.410307 |
10001 rows × 2 columns
feather.write_dataframe(df, "/tmp/br.feather")
R"""
library(feather)
read_feather("/tmp/br.feather")
"""
RCall.RObject{RCall.VecSxp} Source: local data frame [10,001 x 2] br1 br2 <dbl> <dbl> 1 0.00000000 0.000000000 2 -0.77383429 -0.006074936 3 -0.53758071 -0.281177366 4 0.07023901 0.989619762 5 0.91392200 0.272461480 6 0.78325339 0.943957326 7 1.84716072 0.796047645 8 0.44813220 1.478668055 9 -2.35873065 0.106408928 10 -3.03755867 -0.322209156 .. ... ...