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

default values #80

Closed
MikeBadescu opened this issue Aug 25, 2016 · 13 comments
Closed

default values #80

MikeBadescu opened this issue Aug 25, 2016 · 13 comments

Comments

@MikeBadescu
Copy link

Thank you for the great package!

Would it be possible to specify default values in the formals of functions like show(), hide() and toggle? The default values are mentioned in the documentation but not in the source code. Similarly, selector in enable(), disable() could be NULL by default.

This is mostly an annoyance since RStudio is showing Code Diagnostic warnings such as argument 'id' is missing, with no default.

@daattali
Copy link
Owner

When exactly do you see this error? The default values are on the
Javascript by the way
On Aug 25, 2016 09:45, "Mike Badescu" [email protected] wrote:

Thank you for the great package!

Would it be possible to specify default values in the formals of functions
like show(), hide() and toggle? The default values are mentioned in the
documentation but not in the source code. Similarly, selector in enable(),
disable() could be NULL by default.

This is mostly an annoyance since RStudio is showing Code Diagnostic
warnings such as argument 'id' is missing, with no default.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#80, or mute the thread
https://github.com/notifications/unsubscribe-auth/AA6IFOPcqq5STaERiKtN1_HpuRZgi_Vrks5qjcbCgaJpZM4JtRkr
.

@MikeBadescu
Copy link
Author

MikeBadescu commented Aug 25, 2016

This is what I see in RStudio 0.99.1293 (but for many previous versions as well), R 3.3.1 x64 on Windows 10.

shinyjs-warn1
shinyjs-warn2

Edit: all Code Diagnostics enabled in RStudio

@daattali
Copy link
Owner

I do see that now if I enable all the code diagnostics. I find that quite annoying, but more so on RStudio's part. I wouldn't consider this a problem with shinyjs personally. I don't think it's bad practice to have arguments to a function and not give them default values. I would strongly argue that this should not be a "warning" at all, it's a very normal thing to have missing arguments. But maybe the RStudio guys believe otherwise, in which case I'll consider adding defaults.

@MikeBadescu
Copy link
Author

My (subjective) view is that having no default value for an argument implies that the argument must be supplied. Also, style guidelines (e.g. spacing) are not required in R, but they make the code readable. Thank you for considering this.

@daattali
Copy link
Owner

I do see your point, and I will agree with you in general, but the shinyjs functions have all their default values set in the javascript. Initially I just had "..." as the arguments to the functions because all the args are just passed directly into javascript and it's important not to touch them in any way before, and I just documented in the docs what the actual arguments are. But later on I decided it's much better for users to be able to see exactly what arguments are used, so I added the arguments explicitly. But I don't want to give them defaults in R because then they'll have duplicate default values in two places and that feels very wrong, and simply passing along all the params seems like the more correct solution. If javascript was not involved and the entire function was just implemented in R then I'd agree with you, default values would make more sense. And I don't want to just use NULL as default values because in some cases NULL is actually meaningful but sometimes it isn't.

@MikeBadescu
Copy link
Author

I have run into the double defaults issue, it helps to have only one source of defaults, either in the upstream function or in a helper function / dictionary. I am not sure how it would work with JS (not a JS expert). It would be great if it were possible.

(speculating) Maybe the string 'null' could be a default for passing NULL.

Also, thank you for taking your time and asking the community.

@daattali
Copy link
Owner

daattali commented Aug 26, 2016

You can see how the default values are assigned in JS: here and here as an example. The nice thing is that I don't have to worry about what params are passed in and which aren't - JavaScript has a nice "extend" function that deals with that. I really can't think of any way to share common default value between both R and JS... Oh, and 'null' is actually equivalent to NULL in JS so that specifically is not a great solution :p

@daattali
Copy link
Owner

FYI I'm starting to agree with you and think that default values should be provided, but for different reasons. The rstudio warnings are a bit annoying but they shouldn't rule how I write my code 📦

My reason is that I think for the end user it's more convenient to see the default values when they autocomplete the function rather than having to read the documentation to see what they are. I might do that for the next version.

@MikeBadescu
Copy link
Author

Good point. But it will affect many functions ... either use new function names and deprecation warnings or go for shinyjs2 😄

@daattali
Copy link
Owner

daattali commented Mar 17, 2017 via email

@daattali
Copy link
Owner

@MikeBadescu I finally got around to doing this.

I'm very scared something may have broken. If you have a chance at some point, I'd appreciate if you could install from github and make sure your apps still work

@MikeBadescu
Copy link
Author

Dean, thank you!

I installed from GitHub and tested it - so far no issues.

@daattali
Copy link
Owner

daattali commented Nov 12, 2017 via email

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

2 participants