Using quit inside a function in R studio gives a fatal error

Hi All,
I came across this peculiar behaviour of R studio when I tried using q or quit inside a function. When R studio has to deal with such a function, it causes a fatal error as shown in the attached screenshot of the error. But the same function in rgui cause R studio to stop as expected. And similarly using just q () in R studio closes R. It beats me how can q in a function alone cause R studio to crash? I am curious to know if anyone can replicate this issue. Please can anyone give me ideas as to what might be the reason for this error? Thanks in advance.

R Session Aborted
R encountered a fatal error.
The session was terminated
