Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine mrs #8

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Combine mrs #8

wants to merge 14 commits into from

Conversation

persephonet
Copy link
Contributor

I haven't made tests for combineArrays but to be honest I'm not sure anyone else would ever want/need that function

##' description as well as any other variables you would like to combine
##' @return a new variable with combine values from the arrays
##' @export

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to eliminate this space and run make doc again. I suspect this is why you don't have an entry in your NAMESPACE file for these functions.

print(c(subvar.urls, new_subvar.url))
subvars <- subvars[match(urls(subvars),c(subvar.urls, new_subvar.url))]
names(subvars) <- c(subvar.names[na.omit(match(urls(subvars), subvar.urls))], new_subvar.name)
print(names(subvars))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can delete these 6 lines. The three lines below do this more robustly.

##' if false, 'not selected' will be given priority
##' @return a new variable with combined responses from the given variables
##' @export
combineMRs <- function(var1, var2, ..., selectedFirst=TRUE){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I read the tests for this correctly, the purpose of this function is to take the subvariables from two or more MR variables and make a single MR from them--is that right? If so, how about we keep the first MR, unbind the rest, and use addSubvariables to add them to the first? Like:

combineMRs <- function (variable, ...) {
    newsubvars <- unlist(lapply(list(...), unbind)) ## unbind returns the URLs of the unbound variables
    return(addSubvariables(variable, newsubvars))
}

addSubvariables would need to take more than just one subvar, and it would need to accept URLs, but neither are too challenging (and they're more generally useful in that function itself too). And also this way, you wouldn't need separate functions to add to categorical arrays and multiple responses--same function would work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants