-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug in get_clean_sql and add pre-requisite and additional notes o…
…n server naming (#74) * Add pre-requisite and additional notes on server naming * Fix bug in get_clean_sql additional settings that didn't include the SQL query * Increment version number to 0.3.1
- Loading branch information
Showing
7 changed files
with
30 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Type: Package | ||
Package: dfeR | ||
Title: Common DfE R tasks | ||
Version: 0.3.0 | ||
Version: 0.3.1 | ||
Authors@R: c( | ||
person("Cam", "Race", , "[email protected]", role = c("aut", "cre")), | ||
person("Laura", "Selby", , "[email protected]", role = "aut"), | ||
|
@@ -30,4 +30,4 @@ Config/testthat/edition: 3 | |
Encoding: UTF-8 | ||
Language: en-GB | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.3.1 | ||
RoxygenNote: 7.3.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,15 @@ ORCID | |
POSIXct | ||
SSMS | ||
Sys | ||
alt | ||
ay | ||
center | ||
dbplyr | ||
dfeshiny | ||
fy | ||
lauraselby | ||
num | ||
odbc | ||
pkgdown | ||
renv | ||
sep | ||
sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,10 @@ Which you use will depend on how comfortable you are with SQL and R and if you a | |
|
||
For more information on the other two methods, or on troubleshooting the connection between R and SQL in the Department for Education (DfE), please see the [Interacting with a SQL database section of our Analysts' Guide](https://dfe-analytical-services.github.io/analysts-guide/learning-development/r.html#interacting-with-a-sql-database-from-within-r-scripts). | ||
|
||
## Pre-requisites | ||
|
||
To connect to SQL you will need SQL drivers installed. These come as standard currently with the Microsoft SQL Server Management Studio downloads from Department for Education's software center. Make sure to have downloaded the latest version before starting. | ||
|
||
## Connecting to a database | ||
|
||
Usually in the DfE we use a combination of [odbc](https://odbc.r-dbi.org/) and [DBI](https://dbi.r-dbi.org/) to connect to our SQL databases. | ||
|
@@ -50,6 +54,10 @@ con <- DBI::dbConnect(odbc::odbc(), | |
|
||
For advice on finding your database details, or connecting to a SQL database from an R Shiny app that is deployed on a server, please contact the [Statistics Development Team](mailto:[email protected]) who will be able to advise on the setup and steps required. | ||
|
||
Note that your server name may include backslashes, if it does you'll need to make sure to have two backslashes in your R code due to the way that special characters are escaped. | ||
|
||
For example, in SQL Server Management Studio (SSMS) or Azure Data Studio you might call your server `T1PRANMSQL\SQLPROD,60125`, but in R when adding the server name you'd need to call it `T1PRANMSQL\\SQLPROD,60125`. | ||
|
||
## Reading a SQL script into R | ||
|
||
There are a number of standard characters found in SQL scripts that can cause issues when reading in a SQL script within R and we have created the `get_clean_sql()` function to assist with this. Assume you have connected to the database and assigned that connection to a `con` variable, you would then use the following line to read a cleaned version of your SQL script into R. | ||
|
@@ -79,7 +87,7 @@ sql_query_result <- DBI::dbGetQuery( | |
|
||
### Troubleshooting | ||
|
||
Our first advice if you hit an error, would be to check that your SQL script runs in SQL Server Management Studio (SSMS) and is a valid SQL 'SELECT' query that returns a single output. | ||
Our first advice if you hit an error, would be to check that your SQL script runs in SQL Server Management Studio (SSMS) or Azure Data Studio and is a valid SQL 'SELECT' query that returns a single output. | ||
|
||
Assuming that it runs fine in SSMS, the next thing to try is to set additional settings while cleaning the SQL script. You can do this with the `additional_settings` argument in the `get_clean_sql()` function. | ||
|
||
|