error unexpected '}' in function

Could anyone help me check where i'm going wrong with this function? I am trying to adjust Zn_gdl by using the equation shown in myfun but it seems I am doing something wrong

# A tibble: 5 x 4
  Zn_gdl   CRP   AGP try1 
   <dbl> <dbl> <dbl> <lgl>
1   59.4  4.97  0.65 NA   
2   56.2 19.2   1.56 NA   
3   50    1.19  0.61 NA   
4   53.1 13.3   1.07 NA   
5   93.8  5.03  0.8  NA   
> myfun<- function(Zn_gdl,CRP,AGP, data=df) {
+   df$try1=(Zn_gdl-(-0.3502*(CRP)-(-0.8931(AGP-0.37)}
Error: unexpected '}' in:
"myfun<- function(Zn_gdl,CRP,AGP, data=df) {
  df$try1=(Zn_gdl-(-0.3502*(CRP)-(-0.8931(AGP-0.37)}"

I understand the reprex hasn't been done properly but i've just spent an hour try to follow the reprex guidelines and i can't get it render in viewer today

It looks like you have some unpaired/unclosed parentheses. R is looking for these closing parentheses but "unexpectedly" found } instead. :stuck_out_tongue:

I'm not certain where the closing parentheses should go, but I see at least three starting parentheses, open ( that are never paired with closing ).

For example, something like (Zn_gdl-(-0.3502*(CRP)-(-0.8931(AGP-0.37) ))) (note the three additional closing parentheses at the end) would close all pairs. Then you can put the closing curly brace after that.

1 Like

Another possible problem is the absence of * in (-0.8931(AGP-0.37) ).

1 Like

Thanks for the suggestions. I was indeed missing a few parentheses. The * was needed but it didn't solve the problem until I worked on the equation. Turns out I didn't even need to develop a function to get it to work.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.