How to include (source) R script in other scripts

前端 未结 6 907
夕颜
夕颜 2020-12-12 12:10

I\'ve created a utility R script, util.R, which I want to use from other scripts in my project. What is the proper way to ensure that the function this script defines are av

6条回答
  •  悲&欢浪女
    2020-12-12 12:22

    Here is one possible way. Use the exists function to check for something unique in your util.R code.

    For example:

    if(!exists("foo", mode="function")) source("util.R")
    

    (Edited to include mode="function", as Gavin Simpson pointed out)

提交回复
热议问题