# Help wrapping Symbolics.jl for RCall

**URL:** https://discourse.julialang.org/t/help-wrapping-symbolics-jl-for-rcall/114935
**Category:** General Usage
**Tags:** rcall, symbolics
**Created:** [May 29, 2024, 7:54pm UTC](https://discourse.julialang.org/t/help-wrapping-symbolics-jl-for-rcall/114935 "2024-05-29T19:54:24Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sdwfrost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdwfrost/32/2831_2.png) [@sdwfrost](https://discourse.julialang.org/u/sdwfrost)
#### Post date: [May 29, 2024, 7:54pm UTC](https://discourse.julialang.org/t/help-wrapping-symbolics-jl-for-rcall/114935/1 "2024-05-29T19:54:24Z")

</div>

I have a problem that fails due to `Num` (from Symbolics.jl) not being automatically wrapped by RCall.jl. Here’s a minimal example that throws the error:

```Julia
using Symbolics
using RCall

@variables x
@rput x

```

```Julia
ERROR: MethodError: no method matching sexpclass(::Num)

Closest candidates are:
  sexpclass(::SubArray{<:Any, <:Any, <:CategoricalArrays.CategoricalArray})
   @ RCall ~/.julia/packages/RCall/dDAVd/src/convert/default.jl:271
  sexpclass(::Tuple)
   @ RCall ~/.julia/packages/RCall/dDAVd/src/convert/tuple.jl:25
  sexpclass(::AbstractDict)
   @ RCall ~/.julia/packages/RCall/dDAVd/src/convert/default.jl:250

```

I’ve looked at the RCall docs, and have tried a few things, but nothing has worked so far. `Num` is defined as follows:

```Julia
@symbolic_wrap struct Num <: Real
    val
end

```

and `@symbolic_wrap` defined as:

```Julia
macro symbolic_wrap(expr)
    @assert expr isa Expr && expr.head == :struct
    @assert expr.args[2].head == :(<:)
    sig = expr.args[2]
    T = getname(sig.args[1])
    supertype = set_where(sig.args[1], sig.args[2])

    quote
        $expr

        Symbolics.has_symwrapper(::Type{<:$supertype}) = true
        Symbolics.wrapper_type(::Type{<:$supertype}) = $T
        Symbolics.is_wrapper_type(::Type{<:$T}) = true # used in `@register`
        Symbolics.wraps_type(::Type{$T}) = $supertype
        Symbolics.iswrapped(::$T) = true
    end |> esc
end

```

I know I have to define `sexpclass` and `sexp`, but a starting place would be great (the wrapping adds some complexity from the example in the RCall.jl docs)

---

<div class="post-metadata">

### Author: ![sdwfrost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdwfrost/32/2831_2.png) [@sdwfrost](https://discourse.julialang.org/u/sdwfrost)
#### Post date: [May 30, 2024, 4:59pm UTC](https://discourse.julialang.org/t/help-wrapping-symbolics-jl-for-rcall/114935/2 "2024-05-30T16:59:20Z")

</div>

The following code _seems_ to work:

```Julia
using Symbolics
using RCall

x = Num(2)
RCall.sexp(::Type{RCall.Sxp}, x::Num) = RCall.sexp(x.val)
RCall.sexpclass(::Num) = RCall.Sxp

@rput x

```

Any comments on how I do this with non-numeric expressions (`@variables x` instead of `x=Num(2)`)?
