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

defineParameter not working properly #231

Closed
ygc2l opened this Issue Nov 4, 2015 · 6 comments

Comments

Projects
None yet
2 participants
@ygc2l
Contributor

ygc2l commented Nov 4, 2015

Hi Guys,

I am re-writing the metadata for one of my module and defineParameter is now throwing me the following error:

Error in as(NA, class) : 
  no method or default for coercinglogicaltoformula

when I try this:

defineParameter(name = "formula", class = "formula", desc = "Statistical model formula")

I am doing this wrong or it is a bug?

I am using the development branch and here is my sessionInfo():

R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252    LC_MONETARY=English_Canada.1252 LC_NUMERIC=C                   
[5] LC_TIME=English_Canada.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] SpaDES_1.0.3.9010

Thanks,

Jean

@achubaty

This comment has been minimized.

Contributor

achubaty commented Nov 4, 2015

you need to define default values. see ?defineParameter

e.g., caribouMovement sample module:

defineParameter("moveInitialTime", "numeric", 1.0, NA, NA, "time to schedule first movement event")

when default value isn't specified, defineParameter tries to assign a default of NA, which doesn't make sense for a formula class because NA (class "logical") can't be coerced.

@achubaty achubaty closed this Nov 4, 2015

@achubaty achubaty added the invalid label Nov 4, 2015

@ygc2l

This comment has been minimized.

Contributor

ygc2l commented Nov 5, 2015

I already tried to put a default value and I was getting the same error.

So far, I tried the following: default = NULL, default = NA, default = formula(~1), default = ~1, default = "~1".

as(~1, "formula") works in base R.

@achubaty

This comment has been minimized.

Contributor

achubaty commented Nov 9, 2015

Ah I see the problem now. Sorry for prematurely closing. I have a fix in the works.

@achubaty achubaty reopened this Nov 9, 2015

@achubaty achubaty removed the invalid label Nov 9, 2015

@achubaty

This comment has been minimized.

Contributor

achubaty commented Nov 9, 2015

try now

# works
defineParameter(name = "formula", class = "formula", default = formula(~1), desc = "Statistical model formula")

note, you must still specify a default, which needs to match the class specified.

e.g., the following will fail

# missing argument `default` will cause it fail
defineParameter(name = "formula", class = "formula", desc = "Statistical model formula")
@ygc2l

This comment has been minimized.

Contributor

ygc2l commented Nov 9, 2015

Now it works thanks! There is still something funny with the tilde though.

defineParameter(name = "formula", class = "formula", default = formula(~1), desc = "Statistical model formula") returns:

paramName paramClass default min max paramDesc
formula formula ~, 1 NA NA Statistical model formula

For some reasons a "," appears. Note that default = ~1 give me the same outcome. Anyway this is not a blocking bug anymore :)

@achubaty

This comment has been minimized.

Contributor

achubaty commented Nov 10, 2015

that's because it's being stored internally as a list item, which when displayed via the data.frame print mechanism ends up looking different

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment