Skip to content

Commit

Permalink
Now it converts all columns for Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyslom committed Jul 13, 2016
1 parent e0860db commit 0144cd3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pracuj/DESCRIPTION
Expand Up @@ -4,7 +4,7 @@ Version: 0.0.0.9000
Authors@R: person("First", "Last", email = "first.last@example.com", role = c("aut", "cre"))
Description: What the package does (one paragraph).
Depends:
R (>= 3.2.3), RPostgreSQL
R (>= 3.2.3), RPostgreSQL, dplyr, rvest
License: What license is it under?
LazyData: true
RoxygenNote: 5.0.1
11 changes: 5 additions & 6 deletions pracuj/R/get_dbms.R
Expand Up @@ -21,7 +21,7 @@
#'
#' @export

get_dbms <- function(type = 'all') {
get_dbms <- function(type = "all") {
stopifnot(is.character(type))

# scrape data
Expand All @@ -31,10 +31,9 @@ get_dbms <- function(type = 'all') {
scoreNodes <- html_nodes(page, css="th+ .pad-l")

# create data frame
dbms <- data.frame(name = html_text(nameNodes),
dbms <- data_frame(name = html_text(nameNodes),
model = html_text(modelNodes),
score = as.numeric(html_text(scoreNodes)),
stringsAsFactors=F)
score = html_text(scoreNodes) %>% as.numeric)

# clear data
dbms <- dbms %>%
Expand All @@ -48,8 +47,8 @@ get_dbms <- function(type = 'all') {
mutate(model = gsub("Multi-model ", "", model))

# create list of models from multi-models positions
modelList <- strsplit(multiModel$model, ",")
modelList <- setNames(modelList, multiModel$name)
modelList <- strsplit(multiModel$model, ",") %>%
setNames(multiModel$name)

# delete multi-models positions from data frame
dbms <- dbms[-grep(",", dbms$model), ]
Expand Down
9 changes: 6 additions & 3 deletions pracuj/R/get_offers.R
Expand Up @@ -38,12 +38,15 @@ get_offers <- function(dbname = "pracuj", user = "reader", password = "qux94874"

if (description) {
offers <- dbGetQuery(database, "SELECT * FROM offers")
if (windows) {
offers[, 8] <- iconv(offers[, 8], from = "UTF-8", to = "Windows-1250")
}
} else {
offers <- dbGetQuery(database, "SELECT id, href, position, date, location, grade, employer FROM offers")
}

if (windows) {
offers <- sapply(offers, function(column) {
iconv(column, from = "UTF-8", to = "Windows-1250")
}) %>% as_data_frame()
}

suppressWarnings(dbDisconnect(database))
return(offers)
Expand Down

0 comments on commit 0144cd3

Please sign in to comment.