I have the following few lines of code in my R script called assign1.R
:
(u <- c(1, 1, 0, 1, 0)) # a)
u[3] # b)
ones_u <- which(u == 1) # c)
ones_u
source("assign1.R")
Only, the source()
function does not work. R shows me the following error message:
Error in match(x, table, nomatch = 0L) : node stack overflow
Error during wrapup: node stack overflow
What is the problem?
I didn't get exactly the same error you did, but I was able to get something pretty similar with a trivial example:
writeLines("source('badsource.R')",con="badsource.R")
source("badsource.R")
## Error in guess(ll) : node stack overflow
As one of the comments above states, the file you're sourcing is trying to source()
itself.
This is how you would test for that possibility from within R, without just opening the file in a text editor (which is a much more sensible approach):
grepl("source('badsource.R')",readLines("badsource.R"),fixed=TRUE) ## TRUE
(obviously you should fill in the name of your assignment file here ...)
It feels like you should have noticed this yourself, but I'm answering anyway because the problem is delightfully recursive ...
Your are sourcing the file that you are in. That source() line of code should be deleted. If you are sourcing some code from another R file then you would use the source() function, otherwise there is no need to source another file. Also, if all the code works in the one file without running other bits of code in other files, it is likely that you already have the code you need and you wouldn't need to source another file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With