TypeScript code snippet – How to use different scripts in one in R?
# This code is in scriptA.R setwd(dirname(rstudioapi::getActiveDocumentContext()$path)) # set the work directory # to the same file location that the r script is in. WD <- getwd() # get the current working directory print('this is script A') source(paste0(WD,"/scriptB.R")) # loads the functions from that file in this one LOG() # This code is in scriptB.R LOG <- function(){ print('this is script B') } # Both .R files at the same directory # The result is: # this is script A # this is script B