I have a package that requires an environment variable to be set to install the package.
For eg - In a fresh new R session -
devtools::install_github("some_package")
gives an error
Object 'A' not found
If I set that environment variable and then install the package it works and installs the package succesfully.
Sys.setenv(A = 'some_value')
devtools::install_github("some_package")
This is ok to work locally. Now I have a quarto document that uses this package and when I am trying to deploy on Posit Connect it gives me an error in deploy logs.
Installing "some_package"
....
....
Object 'A' not found
I don't know how do I pass this environment variable at the time of deployment.
My failed attempts -
- I have tried setting the environment variable in Posit connect
- In
rsconnect::deployDoc
I saw a new argument called envVars
and I have tried
rsconnect::deployDoc("run_script.qmd", envVars = c(A = 'some_value'))
but this still gives me the same error.
Any ideas/suggestions?
I dont see any mention ov envVars in deployDoc, but it does have its own reference page
maybe try updateAccountEnvVars()
Can you say a little bit more about what the environment variable does that enables the package installation to succeed?
You may need to set the environment variable before the content is deployed, as illustrated here: Posit Connect Documentation - Deploying Content
Sure. The package involves saving and working with data on the network drive. The environment variable sets the path of the network drive where relevant data resides. All the functions in the package require this path to be valid to operate correctly.
How do I set up the environment variable before the content is deployed? Where should this script go?
Set the environment variable: Posit Connect Documentation - Deploying Content
Then hit the deploy endpoint to restore the environment and build the content: Posit Connect Documentation - Deploying Content
You'll probably want to put the script in the directory of the content you want to deploy.
If I am not mistaken is rsconnect
the package which is a wrapper around this API? Can you help me with the corresponding functions that can do this in R? I am not very good with curl commands.
rsconnect
wraps some of the functionality of the API, but if you need more fine-grained control than is offered there, you'll need to call the API yourself. If you're not comfortable with curl you can use httr2.