IDEMSInternational / R-Instat

A statistics software package powered by R
http://r-instat.org/
GNU General Public License v3.0
38 stars 102 forks source link

'By' field does not behave as expected in Climatic > Check Data > Display Daily Data dialog #8309

Open lloyddewit opened 1 year ago

lloyddewit commented 1 year ago

In PR #8307, @rdstern identified the bug below. I understand that the bug can be recreated in English but the behaviour is slightly different in non-English languages. I think the best way to approach this is to first fix the English behaviour. If there are still problems after this in other langauges, then we should raise (and label) a new issue for the translation problem.


There is still a problem with the Climatic > Check Data > Display Daily Data dialogue. Though this still seeems slightly different in non-English, compared to English as I describe below, I can also get the problem in English, so the issue is probably not mainly caused by the language setting. Hence I am approving. Then the issue below should be provided separately.

I think with any climatic dataset, when I press Reset in English I usually get Station in the By field. Notice the Comment field is as follows Code generated by the dialog, Display Daily Data . I now claim that I will get different code at the end of the R command and it will not work. image

Once I complete the dialogue, (with 2 variables) the By field changes to Station-Element - which is correct. But I still get an error and the graph is not produced.

When I return to the dialogue I notice that the Comment has now changed. It now is less informative and just says Code generated by the dialog

It now runs fine.

The old code - with then error is as follows:

# Code generated by the dialog, Display Daily Data
append <- data_book$get_data_frame(data_name="append", stack_data=TRUE, measure.vars=c("tmin","tmax"), id.vars=c("id", "date"))
append <- data_book$get_data_frame(data_name="append", stack_data=TRUE, measure.vars=c("tmin","tmax"), id.vars=c("id", "date"))
last_graph <- ggplot2::ggplot(data=append, mapping=ggplot2::aes(x=date, y=value, colour=variable)) + ggplot2::geom_line() + ggplot2::geom_rug(data=append %>% filter(is.na(value)), colour="black") + theme_grey() + ggplot2::theme(axis.text.x=ggplot2::element_text(), legend.position="none") + ggplot2::facet_wrap(scales="free_y", ncol=1, facet=id ~ variable, labeller=label_wrap_gen(multi_line=FALSE)) + ggplot2::xlab(NULL)
data_book$import_data(data_tables=list(append=last_graph))
data_book$get_data_frame(data_name="append")

The second - correctly running code is:

# Code generated by the dialog
append <- data_book$get_data_frame(data_name="append", stack_data=TRUE, measure.vars=c("tmin","tmax"), id.vars=c("id", "date"))
append <- data_book$get_data_frame(data_name="append", stack_data=TRUE, measure.vars=c("tmin","tmax"), id.vars=c("id", "date"))
last_graph <- ggplot2::ggplot(data=append, mapping=ggplot2::aes(x=date, y=value, colour=variable)) + ggplot2::geom_line() + ggplot2::geom_rug(data=append %>% filter(is.na(value)), colour="black") + theme_grey() + ggplot2::theme(axis.text.x=ggplot2::element_text(), legend.position="none") + ggplot2::facet_wrap(scales="free_y", ncol=1, facet=id ~ variable, labeller=label_wrap_gen(multi_line=FALSE)) + ggplot2::xlab(NULL)
data_book$add_object(data_name="append", object_name="last_graph", object_type_label="graph", object_format="image", object=check_graph(graph_object=last_graph))
data_book$get_object_data(data_name="append", object_name="last_graph", as_file=TRUE)

The last 2 lines are different.

In non-English the By field is initially blank and you may have to complete it manually. The behavior is similar in that the first time (or after reset) it runs differently and gives an error. The second time (assuming you complete the By field) it runs ok.

rdstern commented 1 year ago

@lloyddewit over the weekend we discovered a more general oddity that I also noticed in the English bug above. I suspect this, more general oddity may be related to the language code in some way.

Open any dialogue. I tried the Describe > One Variable > Visualise Data

image

Notice the Comment field does not include the name of the dialogue, which it used to.

If you run this dialogue it runs fine, but the comment is as shown, do the dialogue name is not shown.

If you press the Reset button, then the dialogue name appears.

I had noticed this curiosity in relation to the bug reported here. Possibly not related, but perhaps worth investigating this more general feature first?

Now press