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

Question on R6::R6Class() #1144

Closed
howardbaik opened this issue Mar 15, 2024 · 2 comments
Closed

Question on R6::R6Class() #1144

howardbaik opened this issue Mar 15, 2024 · 2 comments

Comments

@howardbaik
Copy link

howardbaik commented Mar 15, 2024

I was reading the R6 chapter in Advanced R (https://adv-r.hadley.nz/r6.html#r6-classes), which recommends you assign the result of R6Class() into a variable with the same name as the class, because R6Class returns an R6 object that defines the class.

I've been digging into torch, and noticed that some classes follow this recommendation, like LRScheduler, but most classes follow the convention of assigning R6::R6Class(torch_CLASS_NAME) to a variable CLASS_NAME.

I was wondering what the reason for this discrepancy is?

@dfalbel
Copy link
Member

dfalbel commented Apr 23, 2024

We append a torch_ prefix to most class names to avoid clashing s3 classes with other packages that might implement a LRScheduler object that is unrelated to torch.

We could also have named the obejct TorchLRScheduler and then use that as class name, but in general these objects are not exposed directly to users and we provide constructors like nn_module(), optim that correctly add the expected classes.

@howardbaik
Copy link
Author

Okay, thanks for this explanation.

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