How to disable code diagnostics on source

I am translating some code from VBA to R. I have pasted quite of bit of VBA code into my script and I am working on converting it to R. I want to source the script up to where I have placed a stop(). However RStudio insists on checking my entire script for syntax errors before starting. Because there are lots of syntax errors further down, it refuses to source the script.

How can I disable code diagnostics prior to sourcing the script? Thanks.

# I want to source this script

print("print it works!")

stop()

Some_old_VBA_code = that_I_am_translating _
                     + 1

I think you may be misattributing the behaviour to RStudio, when its a documented aspect of the source() function:

Since the complete file is parsed before any of it is run, syntax errors result in none of the code being run

Given that the case I have two possible suggestions for you.

  1. instead of placing stop() as a way to limit the extent of the code that is run, use the # comment to comment out and supress the rest of the file instead.
  2. alternatively write your own function that reads an R file as text, looking for a keyword on each line (i.e. _my_stop_ ) and when this is found, write out a new file to a tempfile which is the original file only up to your stop, and then have your function call source on that ...

i.e. suggestion 2 is to automate suggestion 1

1 Like

Ah thanks. I looked in the source() function hoping to find an option to turn it off but no dice.

Thanks for the suggestions.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.