I want to share some software as a package, but some of my scripts do not seem to be very natural functions. For example, consider the following code fragment, where "raw.df" is a data frame containing variables, both discrete and continuous. The functions "count.unique" and "squash" will be defined in the package. The script divides the data frame into two frames, cat.df, which are considered categorical data, and cts.df, as continuous data.
My idea of how this will be used is that the user will read in the data frame "raw.df", the source of the script, and then interactively edit "cat.df" and "cts.df", possibly combining some categories and conversion of some variables.
dcutoff <- 9 tail(raw.df) (nvals <- apply(raw.df, 2, count.unique)) p <- dim(raw.df)[2] (catvar <- (1:p)[nvals <= dcutoff]) p.cat <- length(catvar) (ctsvar <- (1:p)[nvals > dcutoff]) p.cts <- length(ctsvar) cat.df <- raw.df[ ,catvar] for (i in 1:p.cat) cat.df[ ,i] <- squash(cat.df[ ,i]) head(cat.df) for(i in 1:p.cat) { cat(as.vector(table(cat.df[ ,i])), "\n") } cts.df <- raw.df[ ,ctsvar] for(i in 1:p.cts) { cat( quantile(cts.df[ ,i], probs = seq(0, 1, 0.1)), "\n") }
Now this, of course, could be turned into a function that returns a list containing nvals, p, p.cat, cat.df, etc .; however for me it seems pretty ugly. However, the only condition for including scripts in the package is the "demo" folder, which seems to be inappropriate for the correct path. Consultations on how to proceed will be gratefully received.
(But gratitude would not be formally expressed, as it seems that the use of commentary to express gratitude is outdated.)