Check if loaded renv library matches lockfile

I would like my script to throw an error if the loaded renv library does not match the lockfile. I am currently using the following code:

if (!renv:::renv_project_synchronized_check()) {
    stop()
}

However, I know that it's not ideal to rely on a non-exported function. Is there a better alternative to my current approach?