Import associated `<-` symbols (e.g. like `names<-`) with mod::use
Is it possible, in the new syntax, to make mod::use(raster[crs]) also attach crs<-? I don't think klmr/modules, wahani/modules, or smbache/import can currently do anything like this.
Opening new issue as instructed in #129.
Is there an update on this? Currently box does not work with fun(obj) <- x style calls unless you directly import fun<-.
box::use(so = SeuratObject)
# ... import object etc..
so$DefaultAssay(seurat) <- "RNA"
This yields this error:
Error in Seurat$DefaultAssay(seurat) <- assay :
invalid function in complex assignment
The way around it is this:
box::use(so = SeuratObject[`DefaultAssay<-`])
If it's not possible in the structure of R to allow calls with modules on the LHS of assignment, I think having either a hook for a clear error message Error: box does not support modules on LHS of assignment, if possible, or having documentation that clearly outlines this would be helpful. I love how box makes R a little more pythonic. Bioconductor packages masking select from dplyr is one of the reasons I hate how R handles importing packages.
This yields this error:
Error in Seurat$DefaultAssay(seurat) <- assay : invalid function in complex assignment
Ah. It never previously occurred to me to check this (I am generally not a fan of replacement functions).
As far as I understand this is a hard-coded limitation of R’s interpreter. Because of this I also don’t think I can create a hook to make a clearer error message, except via globalCallingHandlers(), and setting one up unconditionally inside the package startup is complex, brittle and seems to be a bad idea (it will cause package loading to fail in lots of circumstances). But I’ll check whether I can work around this. At any rate, I agree that ‘box’ should clearly document this limitation.
I have asked the R-devel mailing list about this behaviour of R and whether there’s a way around it.
And I am still considering the original feature request — I was previously reluctant because it’s technically a breaking change (probably only theoretically) but the limitation you uncovered makes me reconsider this.