“import as” in R

前端 未结 5 884
清歌不尽
清歌不尽 2020-11-27 17:46

Is there a way to import a package with another name in R, the way you might with import as in Python, e.g. import numpy as np? I\'ve been starting

5条回答
  •  离开以前
    2020-11-27 18:16

    Use the namespace package to generate another namespace aliased to the one you are interested in.

    library(namespace)
    registerNamespace('ggp', loadNamespace('ggplot2'))
    data(iris)
    ggp::ggplot(iris, ggp::aes(x = Petal.Length, y = Sepal.Length)) + ggp::geom_point()
    

    Note this has the disadvantage of making the package versioning/installation requirements more opaque for scripts.

提交回复
热议问题