Search code examples
razureescapingazure-sql-databasestring-formatting

Azure data studio R code execution fails when Random seed set with single quote used as in RNGKind("L'Ecuyer-CMRG")


Code cell execution fails when trying to execute R code with SQL kernel in Azure data studio

EXECUTE sp_execute_external_script
       @language = N'R'
     , @script = N'
       RNGKind("L'Ecuyer-CMRG")
       set.seed(123)
'

Problem is the single quote given in RNGKind("L'Ecuyer-CMRG") closes the single quote opened after @script = N' and throws error. Any thoughts on how to approach it, or perhaps if there is a way to execute script using file name?

Ref: https://learn.microsoft.com/en-us/sql/machine-learning/tutorials/quickstart-r-create-script?view=sql-server-ver15


Solution

  • I tried to repro the issue as, we could avoid such issues using multiple ' in the syntax.

    enter image description here

    It works fine without an error.