dimanche 3 juin 2018

Unexpected 'Else' in "Else" but curly brackets seem correct

Hey i'm having some issues with a part of my code:

data.overview.selection <- NULL

if(is.null(data.overview.selection)){
error.message <- "selected element not present in the datasets"}

if(!is.null(data.overview.selection)){
data.overview <- merge(data.overview.selection, data.overview.TPM, by = 0)  
rownames(data.overview) <- data.overview$Row.names
data.overview <- subset(data.overview, select = -1)
colnames(data.overview)[9] <- "TPM Values"
}
else print(error.message)

This throws the following error: Error: unexpected 'else' in "else"

the variable data.overview.selection is normally a dataframe containing info about a project. I've set it to NULL to create the error message variable. This part works.

Since the data.overview.selection variable is set to NULL, it should, in the next section of the code, trigger the else part and thus print the error message.

However I keep getting the unexpected 'else' in "else" error.

if the data.overview.selection variable isn't NULL, the code does what it's supposed to (without the else statement) i.e merging the 2 variables together and seems to ignore the else statement.

Anyone sees a reason for the error? I've tried adding brackets for the else statement but that doesn't solve the issue.

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire