Skip to content

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


# 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
See also  How to define a function in Python?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.