Coder Social home page Coder Social logo

Comments (7)

leeper avatar leeper commented on May 27, 2024 2

I could imagine that library() could have an ask = interactive() default argument indicating whether to ask the user if they want to install, such that: library("pkg") would fail during non-interactive mode, prompt during interactive mode by default, and not prompt interactively if set explicitly to false (i.e., library("pkg", ask = FALSE).

from wishlist-for-r.

leeper avatar leeper commented on May 27, 2024 1

pacman::p_load() does this.

from wishlist-for-r.

jimhester avatar jimhester commented on May 27, 2024 1

This is not a general solution for R or something I would recommend those new to the language to use, but https://github.com/jimhester/autoinst when used as an error handler will automatically install missing packages for you when they throw an error. It also queries GitHub for R packages if the missing package is not on CRAN, so like I said, not a general solution.

from wishlist-for-r.

HenrikBengtsson avatar HenrikBengtsson commented on May 27, 2024

There are probably several attempts to work around this out there. Here are the ones I am aware of (please let me know of others):

  • pacman::p_load() replaces library() w/ install.packages() iff needed.
  • R.utils::use() - replaces library() and loadNamespace() w/ install.packages() iff needed.

Last updated: 2016-04-27

from wishlist-for-r.

gmbecker avatar gmbecker commented on May 27, 2024

@HenrikBengtsson I really don't think we want an option-based approach here. Mostly because I don't want an option-based approach anywhere really (there are some exceptions). Code that does radically different things based on things external to both code and explicit inputs? No thank you.

I'd say adding an argument is more reasonable. I could see library(, install=) working, though we'd need to think hard about what the default to that should be. I suspect you'll want it to be TRUE, but I'm not sure the case for that is as strong as it might appear (network roundtrip and attempted install in the case of typo ...).

from wishlist-for-r.

HenrikBengtsson avatar HenrikBengtsson commented on May 27, 2024

Another usecase could be pkg::foo(). In that case there is no explicit function call where we can specify an install argument.

I agree that options should not be over/misused, but in some cases I find them really handy. In this case I'd argue that the behavior is more related to the UI rather than function (with stringsAsFactors being extreme example of what we don't want). I don't see how the end results would differ with and without automatic package installation, expect from a time delay.

I also think it is important not to enforce package installation on people, e.g. poor/expensive internet access. This is why I believe it has to be an option.

from wishlist-for-r.

gmbecker avatar gmbecker commented on May 27, 2024

I would argue fairly strongly that pkg::foo() should not install a package, even if library did. I don't think those are interchangeable enough; :: is (semantically, if not implementation-wise) a strict namespacing operation. :: is also used in package code (whether this is good, bad or mixed is an open question and not the topic of discussion here) so we're talking about unexpected installation. The same goes for the require* functions, which would damage how use of suggested packages works now.

So I'd say if this was done, it really should only be done for library, and as an argument.

I guess my deeper question is whether this is really a major annoyance to people? As far as I know, other interpreted languages (python, julia, etc) don't do this, though I must admit I haven't looked.

from wishlist-for-r.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.