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

	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
See also  CSS code snippet - How to link to html in different folder?

Leave a Reply

Your email address will not be published. Required fields are marked *

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