Skip to content

Commit

Permalink
Merge pull request #4 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
fetching latest copy
  • Loading branch information
maxwellfundi committed Apr 11, 2016
2 parents 0a9756b + ebb372f commit 7668a80
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
29 changes: 29 additions & 0 deletions instat/static/InstatObject/R/data_object.R
Original file line number Diff line number Diff line change
Expand Up @@ -663,4 +663,33 @@ data_obj$methods(reorder_factor_levels = function(col_name, new_level_names) {
.self$add_columns_to_data(col_name = col_name, col_data = factor(data[[col_name]], levels = new_level_names))
.self$set_variables_metadata_changed(TRUE)
}
)

data_obj$methods(get_data_type = function(col_name = "") {
if(!(col_name %in% names(data))){
stop(col_name, " is not a column in ", get_metadata(data_name_label))
}
type = ""
if(is.numeric(data[[col_name]])){
type = "numeric"
}

if(is.integer(data[[col_name]])){
if(all(data[[col_name]]>0)){
type = "positive integer"
}else{
type = "integer"
}
}

if(is.factor(data[[col_name]]) & (length(levels(data[[col_name]]))==2)){
type = "2 level factor"
}

if(is.factor(data[[col_name]]) & (length(levels(data[[col_name]]))>2)){
type = "multilevel factor"
}
return(type)
#TODO: This needs to be completed for all possible types e.g. "character", "Date"
}
)
8 changes: 8 additions & 0 deletions instat/static/InstatObject/R/instat_object.R
Original file line number Diff line number Diff line change
Expand Up @@ -533,4 +533,12 @@ instat_obj$methods(reorder_factor_levels = function(data_name, col_name, new_lev

data_objects[[data_name]]$reorder_factor_levels(col_name = col_name, new_level_names = new_level_names)
}
)

instat_obj$methods(get_data_type = function(data_name, col_name) {
if(!is.character(data_name)) stop("data_name must be of type character")
if(!data_name %in% names(data_objects)) stop(paste("dataframe: ", data_name, " not found"))

data_objects[[data_name]]$get_data_type(col_name = col_name)
}
)

0 comments on commit 7668a80

Please sign in to comment.