# How to call my R package by RCall package inside julia?

**URL:** <https://discourse.julialang.org/t/how-to-call-my-r-package-by-rcall-package-inside-julia/51927>\
**Category:** General Usage\
**Created:** [December 16, 2020, 11:59am UTC](https://discourse.julialang.org/t/how-to-call-my-r-package-by-rcall-package-inside-julia/51927 "2020-12-16T11:59:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ravinder\_Ram](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ravinder_ram/32/14617_2.png) [@Ravinder\_Ram](https://discourse.julialang.org/u/Ravinder_Ram)\
**Post date:** [December 16, 2020, 11:59am UTC](https://discourse.julialang.org/t/how-to-call-my-r-package-by-rcall-package-inside-julia/51927/1 "2020-12-16T11:59:17Z")

</div>

if I’ll call my own R package in julia… is my r code will run fast as C?  
I’m guessing here my r code running in julia jit compiler?  
please answer me… please

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [December 16, 2020, 12:03pm UTC](https://discourse.julialang.org/t/how-to-call-my-r-package-by-rcall-package-inside-julia/51927/2 "2020-12-16T12:03:43Z")

</div>

Your question isn’t entirely clear, but I interpret it as “if I use `RCall` to call a package written in R from Julia, will Julia make it faster by compiling it?”

The answer to this question is no: if you use RCall to run code in R from Julia, it will run at the same speed it would have run if you used R directly. You can think of `RCall` as a convenience package that handles the transfer of data back and forth between a Julia and an R process, but any R computations are run in the R process, so there shouldn’t be any changes to runtime speed (modulo some small overhead potentially for passing data).

---

<div class="post-metadata">

**Author:** ![Ravinder\_Ram](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ravinder_ram/32/14617_2.png) [@Ravinder\_Ram](https://discourse.julialang.org/u/Ravinder_Ram)\
**Post date:** [December 16, 2020, 12:12pm UTC](https://discourse.julialang.org/t/how-to-call-my-r-package-by-rcall-package-inside-julia/51927/3 "2020-12-16T12:12:29Z")

</div>

okay… I made R package with juliacall(basically i call my julia code in R) So according to you my julia code run in julia jit compiler… but it is slow I measured the performance why this is happening

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [December 16, 2020, 1:58pm UTC](https://discourse.julialang.org/t/how-to-call-my-r-package-by-rcall-package-inside-julia/51927/4 "2020-12-16T13:58:58Z")

</div>

Sorry I’m not sure I understand - now you’re saying you’re calling Julia code in R, not the other way around? Or are you calling R code using `RCall` in a Julia package, which you then call from R again via `JuliaCall`?

In principle I would expect runtimes using JuliaCall to be the same as when you call the Julia code in Julia (maybe plus a little overhead for shuffling data around), are you finding that that’s not the case?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 16, 2020, 3:59pm UTC](https://discourse.julialang.org/t/how-to-call-my-r-package-by-rcall-package-inside-julia/51927/5 "2020-12-16T15:59:57Z")

</div>

> [@Ravinder\_Ram](#):
>
> is slow I measured the performance why this is happening

There could be many reasons for this, generally impossible to say without code.

First, I would make sure that code is fast when run with Julia directly.

---

<div class="post-metadata">

**Author:** ![Ravinder\_Ram](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ravinder_ram/32/14617_2.png) [@Ravinder\_Ram](https://discourse.julialang.org/u/Ravinder_Ram)\
**Post date:** [December 17, 2020, 10:17am UTC](https://discourse.julialang.org/t/how-to-call-my-r-package-by-rcall-package-inside-julia/51927/6 "2020-12-17T10:17:36Z")

</div>

![Screenshot from 2020-12-17 15-42-03](https://global.discourse-cdn.com/julialang/original/3X/1/6/1677335dfd49be21e893929c614987a638716db6.jpeg)  
sum() takes 160 microsecond → **this is R function**  
j$sum0() takes 7 milisecond → **this is julia function**  
I’m using here juliaconnectoR package  
and juliacall is slower than juliaconnector it takes around 8-9 milisecond

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [December 17, 2020, 10:31am UTC](https://discourse.julialang.org/t/how-to-call-my-r-package-by-rcall-package-inside-julia/51927/7 "2020-12-17T10:31:41Z")

</div>

I mean sure, running functions that take on the order of milliseconds or less to execute is probably not the best use case for cross-language interoperability - I’m not surprised that overhead for this kind of operation is noticeable.

---

<div class="post-metadata">

**Author:** ![Ravinder\_Ram](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ravinder_ram/32/14617_2.png) [@Ravinder\_Ram](https://discourse.julialang.org/u/Ravinder_Ram)\
**Post date:** [December 17, 2020, 10:51am UTC](https://discourse.julialang.org/t/how-to-call-my-r-package-by-rcall-package-inside-julia/51927/8 "2020-12-17T10:51:54Z")

</div>

yeah I agree convert **R object to julia object** takes some time even Rcpp(c++ interface with R) takes 784 microsecond but atleast it should take time same as rcpp.  
if I run this same function directly in julia REPL fast

 ![Screenshot from 2020-12-17 16-20-35](https://global.discourse-cdn.com/julialang/original/3X/6/8/68592bf4441b8e7a7c5fb14fccb75e804d885c3c.jpeg)

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [December 17, 2020, 11:11am UTC](https://discourse.julialang.org/t/how-to-call-my-r-package-by-rcall-package-inside-julia/51927/9 "2020-12-17T11:11:26Z")

</div>

Note that your benchmark here includes compilation time - you should use `BenchmarkTools` and the `@btime` macro to get a more precise estimate of runtime in Julia.
