R Source Code

  • Unknown's avatar

    I’m currently considering placing some source code for the R statistics language online. However I am having trouble with formatting this. I follow the routine:

    [sourcecode language="r"]
    …..
    [/sourcecode]

    However, it appears not to recognise this when I place simple R functions.
    Your help would be much appreciated.
    Blog url: http://ianjacobs.wordpress.com/

  • Unknown's avatar

    Would you be able to send us a sample sourcecode that you’re trying to insert into a post? This will help us try to replicate the problem on our end.

  • Unknown's avatar

    Sure thing…

    [sourcecode language="r"]

    rpois(1000,40)

    require(graphics)

    -log(dpois(0:7, lambda=1) * gamma(1+ 0:7)) # == 1
    Ni <- rpois(50, lambda = 4); table(factor(Ni, 0:max(Ni)))

    1 – ppois(10*(15:25), lambda=100) # becomes 0 (cancellation)
    ppois(10*(15:25), lambda=100, lower.tail=FALSE) # no cancellation

    par(mfrow = c(2, 1))
    x <- seq(-0.01, 5, 0.01)
    plot(x, ppois(x, 1), type=”s”, ylab=”F(x)”, main=”Poisson(1) CDF”)
    plot(x, pbinom(x, 100, 0.01),type=”s”, ylab=”F(x)”,
    main=”Binomial(100, 0.01) CDF”)

    ### Worked Example

    poisson.dist <- rpois(10000,40)
    sort(poisson.dist)
    plot(poisson.dist)
    hist(poisson.dist)

    poisson.dist2 <- rpois(1000,40)
    time1 <- c(1:1000)
    data <- data.frame(time1,poisson.dist2)

    poisson.dist3 <- rpois(10,40)
    time2 <- c(1:10)
    data2 <- data.frame(time1,poisson.dist2)
    plot(data2)

    [/sourcecode]

  • Unknown's avatar

    Hm, I’m able to copy and paste that sourcecode into a test site in both my Visual and HTML editor.

    When you try putting that sourcecode into a blog post, can you let me know what happens? Are you seeing an error message or is some of the code being removed?

  • Unknown's avatar

    Hi,

    Thanks for looking at this. I have just solved the problem. If you look at my test blog entries, the latest entry has worked perfect.

    It appears the the [sourcecode language='r']….[/sourcecode] does not work from the new post entry which appears when I first login to wordpress.com. However, after you mentioned visual and HTML editor, the source code does work from the main admin page.

    Many thanks for your help with this! Much appreciated.

    Ian

  • The topic ‘R Source Code’ is closed to new replies.