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

Impossible to use for floats #2

Open
piiskop opened this issue Dec 25, 2021 · 0 comments
Open

Impossible to use for floats #2

piiskop opened this issue Dec 25, 2021 · 0 comments

Comments

@piiskop
Copy link

piiskop commented Dec 25, 2021

I want the program to state an expression according to the input float. I have four floats, then I let to calculate the minimum of them and then, let switchCase do the rest. My code:

ELEMENTAARLAENG = 1.6E-19 velocity = 20 / 230 / ELEMENTAARLAENG / 8.5E28 / (13 * 1E-3) aInSi = 1 * 1e-3 / 3600 bInSi = 1 * 1e-3 cInSi = 1 dInSi = 1 * 1e3 differenceFromA = deparse(abs(aInSi - velocity)) differenceFromA differenceFromB = deparse(abs(bInSi - velocity)) differenceFromB differenceFromC = deparse(abs(cInSi - velocity)) differenceFromC differenceFromD = deparse(abs(dInSi - velocity)) differenceFromD minimum = deparse(min(c(differenceFromA, differenceFromB, differenceFromC, differenceFromD))) minimum library(switchcase) choice <- switchCase( minimum, alt( ..expr == differenceFromA, NULL, "A" ), alt( ..expr == differenceFromB, NULL, "B" ), alt( ..expr == differenceFromC, NULL, "C" ), alt( ..expr == differenceFromD, NULL, "D" ), alt( NULL, NULL, "E" ) ) choice

This code doesn't run and screams this:

Error in parse(text = cond) : :1:3: unexpected numeric constant
1: ""0.00099999950816447
^
Calls: ... withVisible -> eval -> eval -> switchCase -> eval -> parse
Execution halted

I could also not use deparse however in that case the values for differenceFrom... and minimum would all be different because of the very small difference that R calculates on the background. And comparing these numbers as strings doesn't seem to work in switchCase.

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

1 participant