Skip to content

Namespaces and the package system #9

@flying-sheep

Description

@flying-sheep

Hi, I did my whole PhD doing mostly R and stopped using it then. I authored a few packages, and am the maintainer of the R kernel for Jupyter.

I think you overlooked the number 1 reason why R probably won’t become a serious programming language:

Its packages have two flat namespaces (pkg:::internal and pkg::exported).

That means that

  1. Writing packages will leave you in a symbol jungle of your own creation. All your packages’ files are essentially be concatenated and evaluated in the internal namespace (with access to things you imported in the NAMESPACE file).

    This means you’ll never build bigger, more complex packages that aren’t a complete mess. If you want clean, complex functionality, you’ll have to maintain several smaller packages, which is a high burden for individuals. In contrast, Python’s subpackages solve this effortlessly.

  2. Many useful packages are designed to be library()d, not having their items accessed via ::. This means 2. is very hard to fix, even if there was interest do do so: If you e.g. have pkg1 define a generic gen <- ...; setGeneric('gen') and pkg2 defines both Cls <- setClass('Cls') and setMethod('gen', 'Cls'), you can‘t just do pkg1::gen(pkg2::Cls(...)), since the method isn’t in a visible namespace. This was S4, but S3 has the same problem (and others).

I think CRAN’s more vetted package publishing process (compared to PyPI’s), combined with Python’s namespace system would be ideal. But given the choice, Python is just the better language for building things.

PS: the extremely implicit and underdocumented package building process is also an R problem. Python fixed its own packaging mess by replacing their system. In R, you still have a giant pile of possible files and variables that modify how your package is built, especially if you use Rcpp or so.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions