Skip to main content

Hello,

i was succesfull with static R script insede RCaller transformer. But, when i try to include some FME parametres insede R script like this:

kr = autoKrige(h~1, new_data = grid, input_data = measures, nmax = $(NMAX), maxdist = $(MAXDIST))

I got this error:

Error: unexpected '$' in:

So this is clear syntax error message complaining about $ inside that script. But is there way how can I pass FME parameters to R script inside RCaller?

Hi @dpavlicek, you should be able to use FME parameters within the RCaller in this manner. I have attached a very basic example workspace which shows this: published-params-rcaller.fmw

I have some ideas as to what might be happening:

  1. I'm not familiar with the function, but at least in the latest version of the package, autoKrige() does not expect parameters called nmax or maxdist. Because you are providing them, that might be causing the error? It looks like you might be able to pass them anyway from what I'm reading, but that could be causing problems.
  2. Another option is that you might have either misspelled the user parameter name (you can use the drop-down within RCaller to double-click and add it automatically), or you are providing a value from the user parameter that R doesn't like, likely because it is the wrong data type. If it is the latter case, you can try choosing the right user parameter type (e.g. Number not Text) to match what R expects in the function, or manipulating the value within the RCaller, e.g. as.numeric($(YOUR_USER_PARAM)).
  3. If neither of the above work, you might try simply assigning your user parameters to R variables within the script before using them, e.g. nmax <- $(NMAX). Then you can just reference nmax in the function.

If you require further assistance, we can better help if you post a minimal, reproducible example (see here and here) with data, a workspace, and/or a full R script. Good luck, and please let us know how it goes.


Hi @dpavlicek, you should be able to use FME parameters within the RCaller in this manner. I have attached a very basic example workspace which shows this: published-params-rcaller.fmw

I have some ideas as to what might be happening:

  1. I'm not familiar with the function, but at least in the latest version of the package, autoKrige() does not expect parameters called nmax or maxdist. Because you are providing them, that might be causing the error? It looks like you might be able to pass them anyway from what I'm reading, but that could be causing problems.
  2. Another option is that you might have either misspelled the user parameter name (you can use the drop-down within RCaller to double-click and add it automatically), or you are providing a value from the user parameter that R doesn't like, likely because it is the wrong data type. If it is the latter case, you can try choosing the right user parameter type (e.g. Number not Text) to match what R expects in the function, or manipulating the value within the RCaller, e.g. as.numeric($(YOUR_USER_PARAM)).
  3. If neither of the above work, you might try simply assigning your user parameters to R variables within the script before using them, e.g. nmax <- $(NMAX). Then you can just reference nmax in the function.

If you require further assistance, we can better help if you post a minimal, reproducible example (see here and here) with data, a workspace, and/or a full R script. Good luck, and please let us know how it goes.

HI @samatsafe, thank you for your time. It turns out that I messed up my workspace somehow, so my parameters were not defined. Now, after recheck, everything works fine. Just one note.. nmax and maxdist are parameters of gstat.krige function which is used underneath autoKrige. Thus you can pass any valid gstat.krige paramater as keyworded argument to autoKrige.


HI @samatsafe, thank you for your time. It turns out that I messed up my workspace somehow, so my parameters were not defined. Now, after recheck, everything works fine. Just one note.. nmax and maxdist are parameters of gstat.krige function which is used underneath autoKrige. Thus you can pass any valid gstat.krige paramater as keyworded argument to autoKrige.

Great to hear your got it working, @dpavlicek. And yes, thanks for explaining how autoKrige works, that makes sense. Please let us know if you need help with anything else.


Reply