What's the ugliest line of R code that still parses?

72 96 characters.

`c`<-function(...){list(...)[[-1]];}->>`c`;`[`=0;`]`=10;c(c,c)(c,c)(c,invisible)(`[`[]:`]`[])[];

Ugliness:

  • Reusing a standard function name
  • Using symbols as variable names
  • Global assignment
  • Right assignment
  • Self-redefinition of function
  • Unnecessary trailing semicolon(s)
  • Unnecessary sub-scripting numbers
  • Unnecessary quoting of variable name
  • Leaves the workspace in a state which will almost certainly break any subsequent code run

Generates the sequence 0-10 (thanks to Andrie for the idea to do that).

output:

 [1]  0  1  2  3  4  5  6  7  8  9 10

Generate a sequence from 0 to 10.

100 characters

{.=0;for(`~1` in c(1,2,3,4,5,6,7,8,9,10)){.=c(., `~1`,recursive=F)};print(unname(.[drop=T]));rm(.)}
 [1]  0  1  2  3  4  5  6  7  8  9 10

100 characters: Generate a sequence from 1 to 10.

Note that the numbers 2-10 are NOT in the code... - Bonus points? :-)

Also note that it uses lapply for maximum performance :)

unlist(lapply(LETTERS[-(11:26)],function(x) as.integer(charToRaw(x))-as.integer(charToRaw('A'))+1L))
#[1]  1  2  3  4  5  6  7  8  9 10