UPDATE: 26 October 2023
The full function (and the Manningtrap_critical function) can be viewed at https://gitlab.com/iembry/iemisc/-/raw/master/R/Manningtrap.R.
UPDATE: 25 October 2023
The HTML Web page can be seen online at https://gitlab.com/iembry/iemisc/-/blob/master/inst/www/manningtrap.html
I am testing out the Manningtrap function from my iemisc
package with opencpu
. The Manningtrap function can be viewed online at https://gitlab.com/iembry/iemisc/-/blob/master/R/Manningtrap.R.
I attempted to test the following example with the HTML form (see the code & image below):
library(iemisc)
Manningtrap(y = 1.454, b = 4, m = 3, Sf = 0.02, n = 0.0550, units = "Eng", type = "symmetrical",
output = "data.table")
The following code shows the JavaScript code used to process the variables obtained from the HTML form:
//init this script when the page has loaded
$(document).ready(function(){
$("#submitbutton").on("click", function(){
//disable the button to prevent multiple clicks
$("#submitbutton").attr("disabled", "disabled");
//read the value for 'Q'
var Q = $("#Qfield").val();
var Q = $("#Qfield").val();
if(Q == ""){
$("#Qfield").val("null");
}
//read the value for 'n'
var n = $("#nfield").val();
var n = $("#nfield").val();
if(n == ""){
$("#nfield").val("null");
}
//read the value for 'm'
var m = $("#mfield").val();
var m = $("#mfield").val();
if(m == ""){
$("#mfield").val("null");
}
//read the value for 'm1'
var m1 = $("#m1field").val();
var m1 = $("#m1field").val();
if(m1 == ""){
$("#m1field").val("null");
}
//read the value for 'm2'
var m2 = $("#m2field").val();
var m2 = $("#m2field").val();
if(m2 == ""){
$("#m2field").val("null");
}
//read the value for 'Sf'
var Sf = $("#Sffield").val();
var Sf = $("#Sffield").val();
if(Sf == ""){
$("#Sffield").val("null");
}
//read the value for 'y'
var y = $("#yfield").val();
var y = $("#yfield").val();
if(y == ""){
$("#yfield").val("null");
}
//read the value for 'b'
var b = $("#bfield").val();
var b = $("#bfield").val();
if(b == ""){
$("#bfield").val("null");
}
//read the value for 'Temp'
var Temp = $("#Tfield").val();
var Temp = $("#Tfield").val();
if(Temp == ""){
$("#Tfield").val("null");
}
//read the value for 'units'
var units = $("#unitsfield").val();
//read the value for 'type'
var type = $("#typefield").val();
//read the value for 'output'
var output = $("#outputfield").val();
//perform the request
var req = ocpu.rpc("Manningtrap", {
Q : Q,
n : n,
m : m,
m1 : m1,
m2: m2,
Sf : Sf,
y : y,
b : b,
Temp : Temp,
units : units,
type : type,
output : output
}, function(result){
$("#result").text(result.message);
});
//if R returns an error, alert the error message
req.fail(function(){
alert("Server error: " + req.responseText);
});
//after request complete, re-enable the button
req.always(function(){
$("#submitbutton").removeAttr("disabled")
});
});
});
When the JavaScript function is executed (see the image below showing the form results), the following error message is incurred:
Server error: Either Q, n, m, m1, m2, Sf, b, or y is 0, NA, NaN, Inf, -Inf, empty, or a string. Please try again.
Backtrace:
[90m [39m▆
[90m 1. [39m├─[1mevaluate[22m::evaluate(...)
[90m 2. [39m│ └─evaluate:::evaluate_call(...)
[90m 3. [39m│ ├─evaluate (local) timing_fn(...)
[90m 4. [39m│ ├─evaluate (local) handle(...)
[90m 5. [39m│ │ └─[1mbase[22m::try(f, silent = TRUE)
[90m 6. [39m│ │ └─base::tryCatch(...)
[90m 7. [39m│ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
[90m 8. [39m│ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
[90m 9. [39m│ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
[90m 10. [39m│ ├─base::withCallingHandlers(...)
[90m 11. [39m│ ├─base::withVisible(...)
[90m 12. [39m│ └─[1mevaluate[22m:::eval_with_user_handlers(expr, envir, enclos, user_handlers)
[90m 13. [39m│ └─[1mbase[22m::eval(expr, envir, enclos)
[90m 14. [39m│ └─base::eval(expr, envir, enclos)
[90m 15. [39m│ └─iemisc::Manningtrap(...)
[90m 16. [39m│ └─[1massertthat[22m::assert_that(...)
[90m 17. [39m│ └─[1mbase[22m::stop(assertError(attr(res, "msg")))
[90m 18. [39m└─[1mevaluate[22m (local) `<fn>`(`<assrtErr>`)
[90m 19. [39m └─output_handler$error(e)
In the Manningtrap function, the Temp, Q, m1, and m2 parameters are defined in the function as Temp = NULL, Q = NULL, m1 = NULL, and m2 = NULL when those parameters are absent from the function call.
What is the best method to replicate the Manningtrap function with the aforementioned NULL values in the JavaScript function?