Reputation: 670
I have script like:
library('RPostgreSQL')
source('credentials.R') # Defines USERNAME, PASSWORD, DBNAME, PORT, and HOST
postgres <- dbConnect(PostgreSQL(),
user=USERNAME,
password=PASSWORD,
dbname=DBNAME,
port=PORT,
host=HOST)
results <- dbGetQuery(postgres, "SELECT * FROM table;")
The script runs fine from RStudio, but when I run it as a data source in Power BI, 'credentials.R'
is not found. How do I run this?
Upvotes: 0
Views: 54
Reputation: 670
The issue is the working directory. Within RStudio, the console is in the directory that contains 'credentials.R'
. Add the following line to the beginning of your script:
setwd('/path/to/working/directory')
Upvotes: 1