<commit_before># Generic query wrapper to keep the MySQL nastiness out of the code.
dbquery <- function(db, query, mysqlhost="mysql.external.legion.ucl.ac.uk", mysqlport = 3306) {

# Pull in the RMySQL library and my tool for reading Python ini files.
  (library(RMySQL))
  source("r/rini.r")

# Get authentication information.
  authdetails <- rinisect("~/.stats_secrets/accounts", "database")

  con <- dbConnect(MySQL(),
                 user = authdetails['user'],
                 password = <PASSWORD>details['<PASSWORD>'],
                 dbname = db,
                 host = mysqlhost,
                 port = mysqlport)

  on.exit(dbDisconnect(con))

  q <- dbSendQuery(con, query)
  data <- fetch(q)
  stat <- dbHasCompleted(q)

  dbClearResult(q)

  return(data)
}

# Convert list-like structures to an SQL list.
sqllist <- function(rlist) {
  sqlstr <- "("

  if (typeof(rlist) == "character") {
    sqlstr <- paste(sqlstr, "'", sep="")
    sqlstr<-paste(sqlstr, rlist, sep="")
    sqlstr <- paste(sqlstr, "'", sep="")
  } else {
    for (a in rlist) {
      if (sqlstr != "(") {
        sqlstr <- paste(sqlstr, ",", sep="")
      }
      sqlstr <- paste(sqlstr, "'", sep="")
      sqlstr <- paste(sqlstr, a, sep="")
      sqlstr <- paste(sqlstr, "'", sep="")
    }
  }
  sqlstr <- paste(sqlstr, ")", sep="")
  return(sqlstr)
}<commit_msg>Add R version of the onlimits code.<commit_after># Generic query wrapper to keep the MySQL nastiness out of the code.
dbquery <- function(db, query, mysqlhost="mysql.external.legion.ucl.ac.uk", mysqlport = 3306) {

# Pull in the RMySQL library and my tool for reading Python ini files.
  (library(RMySQL))
  source("r/rini.r")

# Get authentication information.
  authdetails <- rinisect("~/.stats_secrets/accounts", "database")

  con <- dbConnect(MySQL(),
                 user = authdetails['user'],
                 password = <PASSWORD>['<PASSWORD>'],
                 dbname = db,
                 host = mysqlhost,
                 port = mysqlport)

  on.exit(dbDisconnect(con))

  q <- dbSendQuery(con, query)
  data <- fetch(q)
  stat <- dbHasCompleted(q)

  dbClearResult(q)

  return(data)
}

# Convert list-like structures to an SQL list.
sqllist <- function(rlist) {
  sqlstr <- "("

  if (typeof(rlist) == "character") {
    sqlstr <- paste(sqlstr, "'", sep="")
    sqlstr<-paste(sqlstr, rlist, sep="")
    sqlstr <- paste(sqlstr, "'", sep="")
  } else {
    for (a in rlist) {
      if (sqlstr != "(") {
        sqlstr <- paste(sqlstr, ",", sep="")
      }
      sqlstr <- paste(sqlstr, "'", sep="")
      sqlstr <- paste(sqlstr, a, sep="")
      sqlstr <- paste(sqlstr, "'", sep="")
    }
  }
  sqlstr <- paste(sqlstr, ")", sep="")
  return(sqlstr)
}


# Build owner limit string for queries.
onlimits <- function(users="*") {
  query <- ""

# If we don't have the default value, build a limit on the query.
  if (users != "*") {
    userlist <- sqllist(users)
    query <- paste(query, " and owner in ", sep="")
    query <- paste(query, userlist, sep="")
  }

  return query
}
{'fraction_non_alphanumeric': 0.16934689858877586, 'fraction_numerical': 0.002625533311453889, 'mean_word_length': 2.667870036101083, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3979738', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1005, 'n_words': 260}