RCall API

1. rcopy() method

The rcopy() method is used to convert the RObjects into Julia objects. We will use the R_string method inside of rcopy() so that the output the R_string returns will be converted into Julia objects. we will use the rcopy() function in the Julia prompt not in the R prompt.

Example 1:

Julia




julia> rcopy(R"c(10,20)")
2-element Vector{Float64}:
 10.0
 20.0


Output

Example 2:

Julia




R"arr <- c(1,2,3,4)"
  
julia_arr = rcopy(R"arr")


Output

2. @reval

The reval function is used to evaluate R codes in the Julia environment. It is visible in the function name that it stands for R-eval means evaluating R codes in Julia’s environment. It takes a string parameter that consists of some R code. Evaluates the expression and return the result in Julia object.

Julia




using RCall
  
total = reval("sum(c(1,2,3,4,5))")


Output

3. @rcall

The rcall function of RCall package is used to call any R functions in the current Julia environment. It requires the RCall package to be imported and used.the

Julia




using RCall
  
res = rcall(:mean,1:5)


Output

4. @robject

The robject function is used to convert a Julia variable or object into R object. It is useful to transfer results or anything computed in Julia’s environment into the R environment.

Julia




value = 10
  
typeof(value) # Returns Int64
  
value = robject(10) # Converting into R object
  
# Returns RObject{IntSxp}
# [1] 10
  
typeof(value)
# Returns - RObject{IntSxp}


Output

Int64
RObject{IntSxp}
[1] 10
RObject{IntSxp}

Julia – RCall

To bridge the gap between the R language, which has been in the scene for a long time and is renowned for its huge collection of statistical and data analysis packages, and one of the newest members, Julia, which is a high-level programming language, the package RCall has been developed. using the RCall package, the developers can use the power and features of both languages simultaneously. use the libraries of R in Julia or vice versa. Even developers can run R code from the Julia prompt, transfer variables, etc. It allows seamless integration of R’s functionality within a Julia environment.

Similar Reads

Prerequisites

1. The R language and Julia language both must be installed on the user’s device....

Implementation

Now we will convert the Julia prompt into an R prompt. While in the same command line/ terminal press the SHIFT+$ key together, and the prompt will change from Julia to R. Now to go back to Julia we will just press the BACKSPACE once....

RCall API

...

The @rlibrary and @rimport Macros

...

Contact Us