Scripts relacionados con el acceso y análisis en bases de datos Access.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
1.5 KiB

  1. ---
  2. title: "sqlFunctions-Doc"
  3. output:
  4. html_document:
  5. toc: true
  6. toc_depth: 2
  7. ---
  8. ```{r setup, include=FALSE}
  9. knitr::opts_chunk$set(echo = TRUE)
  10. ```
  11. ---
  12. ## sqlDropLast
  13. ### Description
  14. Removes from Database the last (or the amount specified) entry.
  15. ### Usage
  16. sqlDropLast(conn, tablename, droplast=1)
  17. ### Arguments
  18. Argument|Description
  19. ---|---
  20. conn|connection handle returned by odbcConnect.
  21. tablename|character: a database table name accessible from the connected DSN.
  22. droplast|the amount of lines to be removed from the table strating from tail. By default, it removes only 1 line.
  23. ### Details
  24. Removes from Database the last (or the amount specified) entry.
  25. ### Value
  26. Invisibly for success (and failures cause errors).
  27. ### Examples
  28. ```r
  29. dta<-odbcConnect("test")
  30. sqlDropLast(dta, "TableTest")
  31. ```
  32. ### Function
  33. ```r
  34. sqlDropLast<-function(conn, tablename, droplast=1){
  35. table<-sqlFetch(conn, tablename)
  36. table<-table[1:(nrow(table)-droplast),]
  37. sqlSave(conn, table, tablename = tablename, safer = F)
  38. }
  39. ```
  40. ---
  41. ## sqlInitizalize
  42. ### Description
  43. Loads required libraries and gets the db location.
  44. ### Usage
  45. sqlInitialize()
  46. ### Arguments
  47. Argument|Description
  48. ---|---
  49. ### Details
  50. Loads required libraries and gets the db location from "ruta_database.R" file.
  51. ### Value
  52. Invisibly for success (and failures cause errors).
  53. ### Examples
  54. ```r
  55. sqlInitialize()
  56. ```
  57. ### Function
  58. ```r
  59. sqlInitialize<-function(){
  60. library(tidyverse)
  61. library(RODBC)
  62. library(openxlsx)
  63. ## Conexión a la base de datos
  64. source("ruta_database.R", encoding = "UTF-8")
  65. }
  66. ```