0

Can anybody help with the following syntax:

with(predict(spl_bin,
             dosex_bin,
             xref_bin,
             expo = TRUE),{
               plot(get("rcs(dose,knots_bin)dose"), 
                    pred,
                    type="l", 
                    ylim=c(0.4,10), 
                    ylab="cardiovascular disease relative risk", 
                    xlab="alcohol consumption (g/d)", 
                    log ="y", 
                    bty="l", 
                    las=1)
               matlines(get("rcs(dose,knots_bin)dose"), 
                        cbind(ci.ub, ci.lb), 
                        col = 1, 
                        lty = "dashed")
               })

I have tried to fix the above-mentioned syntax with no success. The following message always came up:

> unexpected symbol in 
"with(predict(spl_bin,dosex_bin,xref_bin,expo = TRUE),{plot(get("rcs(dose,knots_bin)dose"), pred,type="l", ylim=c(0.4,10), ylab="cardiovascular disease relative risk", xlab="alcohol consumption"

Any help will be appreciated. I am new with R and have so much to learn.

DaveArmstrong
  • 18,377
  • 2
  • 13
  • 25
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. If we can't copy/paste the code for testing, it's much harder to help you. – MrFlick Dec 15 '22 at 19:48
  • You can `get` an object, but you can't get a function of an object. If I have `x = 1:3`, `get("x")` works but `get("mean(x)")` doesn't. With only this non-reproducible code shared, it's not clear why you're using `get` at all... you could maybe use `eval(parse())` but usually there's a better way. If you can provide more context and make your example reproducible we can help much better. – Gregor Thomas Dec 15 '22 at 20:08
  • I don't get that syntax error since @DaveArmstrong reformatted your code. I think the comments are on the mark for why the current code won't work, but it would probably be better to start with a whole new question. – user2554330 Dec 15 '22 at 20:58
  • Ah. I see Dave edited out the syntax error when formatting the code. You can't have have two statements next to each other on the same line with nothing in between. You either need a new line, or you need a semi-colon to separate them. So you'd need something like `plot(...); matlines(...)` if you really wanted to keep that on one line, but with a line that long, you really should consider splitting it up for clarity. – MrFlick Dec 15 '22 at 21:57
  • I'm using the same syntax in the pdf available on this site https://cran.r-project.org/web/packages/dosresmeta/vignettes/dosresmeta.pdf The syntax is on the page 11 of the PDF. I don't get it why the same syntax can be run by me. Any help is appreciated – Joshua Henrina Dec 17 '22 at 10:49

0 Answers0