Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"is.na() applied to non-(list or vector) of type 'language'" when passing a Julia's boolean variable to R's smooth.spline #499

Open
szcf-weiya opened this issue Sep 7, 2023 · 2 comments

Comments

@szcf-weiya
Copy link
Contributor

I encounter the problem when passing a boolean variable to smooth.spline.

julia> a = true

julia> x = rand(100);

julia> y = x;

julia> R"smooth.spline($x, $y, cv=$a)"
RObject{VecSxp}
Call:
smooth.spline(x = `#JL`$x, y = `#JL`$y, cv = `#JL`$a)

Smoothing Parameter  spar= 0.2607728  lambda= 7.905905e-08 (18 iterations)
Equivalent Degrees of Freedom (Df): 43.86631
Penalized Criterion (RSS): 1.62104e-30
Error showing value of type RObject{VecSxp}:
ERROR: REvalError: Warning in is.na(cv) :
  is.na() applied to non-(list or vector) of type 'language'
Warning in if (!is.na(cv)) cat(if (cv) "PRESS(l.o.o. CV): " else "GCV: ",  :
  the condition has length > 1 and only the first element will be used
Warning in if (cv) "PRESS(l.o.o. CV): " else "GCV: " :
  the condition has length > 1 and only the first element will be used
Error in if (cv) "PRESS(l.o.o. CV): " else "GCV: " : 
  argument is not interpretable as logical

It works well if with R's own boolean variable TRUE

julia> R"smooth.spline($x, $y, cv=TRUE)"
RObject{VecSxp}
Call:
smooth.spline(x = `#JL`$x, y = `#JL`$y, cv = TRUE)

Smoothing Parameter  spar= 0.2607728  lambda= 7.905905e-08 (18 iterations)
Equivalent Degrees of Freedom (Df): 43.86631
Penalized Criterion (RSS): 1.62104e-30
PRESS(l.o.o. CV): 1.721696

The error message indicates that it failed at the print.smooth.spline step (https://github.com/wch/r-source/blob/1af6b4aa417e106d63687992e229f461d45a30d9/src/library/stats/R/smspline.R#L319-L321)

image

The fitting procedure is OK. And if I append ; to hide the message, no error is thrown,

julia> R"smooth.spline($x, $y, cv=$a)";

I'm quite curious about why the error is triggered. How should we fix it?

I am using Julia 1.8.1 + RCall v0.13.14 (R3.6.3)

@palday
Copy link
Collaborator

palday commented Sep 7, 2023

Can you try using the most recent version of RCall (0.13.17)? I don't get an error message with RCall 0.13.17 and R 4.2. I'm guessing it's easier to upgrade RCall than R and the relevant part of the R printing source hasn't changed:

    if (!is.na(cv <- x$cv)) 
        cat(if (cv) 
            "PRESS(l.o.o. CV): "
        else "GCV: ", format(x$cv.crit, digits = digits), "\n", 
            sep = "")

@szcf-weiya
Copy link
Contributor Author

I tried

  • Julia 1.9.1 + RCall 0.13.17 (R 3.6.3)
  • Julia 1.8.2 + RCall 0.13.16 (R 4.1.0)

Both throw the same error message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants