r

R Script: Determine whether the script is run in the GUI or from command line

Is it possible to determine - from within the script - whether the script is running in the R-GUI (specifically R.app on OS X) or whether it has been called from Terminal/command line (i.e. R --vanilla -f script.R)? If so, how is this possible? I'm asking because I have a script that can run parallelized (using the doMC library), which ...

Inner Sort with R - Once by Numeric then by Alpha (V2)

Hello, I have asked this question before and received a solution, but my problem is somewhat varied from the original explanation I have a data frame, like this: nums<-c(5,7,8,9,10,3,2,1) text<-c("Company a","Company b","Company c","Company d","Company a 09","Company b 09","Company c 09","Company d 09") this <- data.frame() this <-...

How to plot nice graph using few commands, separating drawing logic from layout?

Is there a simple way to make a nice plot of the following data in R, without using many commands? Region1 Region2 2007 17 55 2008 26 43 2009 53 70 2010 96 58 I do know how to plot the data, but it uses too many commands and parameters, and the result still looks absolutely terrible (see here): > test <- read.table("/tmp/data.txt") ...

Grouping rows or columns of data in R

I'm trying to import some data into R and not having much luck grouping together rows of related data. Example: There a set of problems such as {A, B, C, D}. Each problem has two variables of interest which are being measured: "x" and "y". Each variable is analysed in terms of some simple statistics: min, max, mean, stddev. So, my in...

R language: Dynamically create R graphics for webpage

Hi guys, I've spent a few weeks learning some R and I'm floored at just how slick and powerful it is. I'm using it to plot some data returned from an SQL query, and I'd like to be able to share those plots with others I work with through a web portal. I realize I can create a cron job to run the R scripts on the webserver to create t...

What statistics should a programmer (or computer scientist) know?

I'm a programmer with a decent background in math and computer science. I've studied computability, graph theory, linear algebra, abstract algebra, algorithms, and a little probability and statistics (through a few CS classes) at an undergraduate level. I feel, however, that I don't know enough about statistics. Statistics are increasin...

how to import data with line breaks from text file into R?

I have a text file that I'd like to import into R. Problem is, the file looks like this: x1,x2,x3,x4,x5,x6,x7,x8,x9,10,x11 1953.00 7.40000 159565. 16.6680 8883.00 47.2000 26.7000 16.8000 37.7000 29.7000 19.4000 1954.00 7.80000 162391. 17.0290 8685.00 ...

Ordering Merged data frames

Hi all As a fairly new R programmer I seem to have run into a strange problem - probably my inexperience with R After reading and merging successive files into a single data frame, I find that order does not sort the data as expected. I have multiple references in each file but each file refers to measurement data obtained at a diffe...

Using the 'available.packages' Function to Retrieve Emails

Hello, I am attempting to retrieve email addresses of contributing package authors and maintainers to the R-Project. The function reads as follows: availpkgs <- available.packages(contriburl = contrib.url(getOption("repos"), type), method, fields = NULL, type = getOption("pkgType"), filt...

Why my bash can't execute R script ?

My script use an access to mysql to get command arguments to launch Rscript. Its use is as follows : Rscript $RFILE $ARGUMENTS (RFILE corresponding to path to Rscript, and ARGUMENTS corresponding to path file used and agr). I try, different way, but I still have errors, here a copy of my bash script : #!/usr/bin/env bash # Execute R pr...

How to save R plot image to database?

I'd like to save a plot image directly to the database. Is the best way in R to do this: Write the plot image (png) to the filesystem Read the file that was written Send the file to the database via query (RODBC) Ideally I'd like to combine steps 1 and 2 above by simply write the png image to a binary connection. Does R support thi...

Using R with Apache & PHP

Is there anyway to run R scripts through Apache and PHP? I would like to be able to pass variables from PHP to R. Has anyone done something like this? Essentially, I would like to know if there is a method for passing variables from PHP to R on an apache server. ...

Creating a new variable from a conditional operation on 3 old variables in R

Hi, I have a dataset in R, which contains the results of a rapid diagnostic test. The test has a visible line if it is working properly (control line) and a visible line for each of the two parasite species it detects, if they are present in the patient sample. The dataset contains a logical column for each test line, as follows: (dat...

Create Editable plots from R

Hello, I'm creating a series of plots in R (I'm using ggplot2, but that's not essential) and I want to be able to save my output so I can then edit it for furthur use, For instance, I might want to move legends about, or adjust colours etc. I have seen that ggplot2 has a save command but that seems to produce pdf's or bitmaps, neither ...

Creating a facet_wrap plot with ggplot2 with different annotations in each plot

I am using ggplot2 to explore the result of some testing on an agent-based model. The model can end in one of three rounds per realization, and as such I am interested in how player utilities differ in terms of what round the game ends and their relative position in 2D space. All this is to say that I have generated a facet_wrap plot t...

How to Correctly Use Lists in R?

Brief background: Many (most?) modern programming languages in widespread use have at least a handful of ADTs in common, in particular, string (a (sequence comprised of characters), list (an ordered collection of values), and a map-based type (an unordered key-value store). In the R, the first two are implemented as 'character' and 'vect...

Transform R dataframes using variables in loop

I am trying to replace values in a R dataframe by column. I would like to loop though a given list of columns of the dataframe and replace all "Yes" values by 1 and all the other values by 0. I tried to do this using transform() and ifelse() functions with the something like this: # List of selected Columns: ColumnNames = c("Frigori", ...

long/bigint/decimal equivalent datatype in R

What datatype choices do we have to handle large numbers in R? By default, the size of an integer seems to be 32bit, so bigint numbers from sql server as well as any large numbers passed from python via rpy2 get mangled. > 123456789123 [1] 123456789123 > 1234567891234 [1] 1.234568e+12 When reading a bigint value of 123456789123456789 ...

Using outer() with predict()

I am trying to use the outer function with predict in some classification code in R. For ease, we will assume in this post that we have two vectors named alpha and beta each containing ONLY 0 and 1. I am looking for a simple yet efficient way to pass all combinations of alpha and beta to predict. I have constructed the code below to mi...

Pipe R commands and results from within a for loop to a file

We want to log the commands and results of a R script into a text report file. The pipe into the text file works well with sink(), but not within a for loop. The script is called with source("myscript.r",echo=TRUE) We need the loop to extract all rows of a data.frame consecutively into a vector and do some vector based analysis with ...