Displaying 20 results from an estimated 10000 matches similar to: "Confusion regarding environments invoked by "source" command"
2011 Oct 28
3
program never enters browser mode when I add browser()
Dear All
I have a program that breaks at the following lines of code:
bigfunction =
{
...
object1 = myfunction(x)
object2 = strsplit(object1, ",")[[1]]
...
}
where myfunction is defined elsewhere outside of bigfunction.
The error I get is "error in strsplit() -- object1 not found".
However, when I insert browser() into my code so that the above reads,
bigfunction =
{
2011 Apr 07
1
Adding text to page margin with lattice graphics
R: 2.12.1
OS X
Colleagues
I am working with lattice graphics for the first time and I am confused by some aspects of controlling these graphics. The most pressing issue is the following:
I can print the graphics without problems with the command:
print(MYFUNCTION(SOMEOBJECT)
However, I would like to add margin text (this terminology might not apply in this setting). I am able to do so with
2005 Jul 22
3
Question regarding subsetting
I run R 2.1.1 in a Linux environment (RedHat 9) although my question
is not platform-specific.
Consider the following:
> A <- c("Prefix-aaa", "Prefix-bbb", "Prefix-ccc")
> B <- strsplit(A, "-")
> B
[[1]]
[1] "Prefix" "aaa"
[[2]]
[1] "Prefix" "bbb"
[[3]]
[1] "Prefix" "ccc"
How
2008 Oct 12
2
proper use of textConnection
Colleagues,
Using R2.7.0 in OS X, I am having trouble understanding the command
textConnection. My situation is as follows:
1. I am trying to read a lengthy file (45000 lines) that has headers
~ every 1000 lines. read.table (or its variants) fail because of the
recurrent headers.
2. My present approach is the following:
a. use readLines to read the file, save as an array
b. use grep
2009 Jun 03
1
Using constrOptim() function
I have a function myFunction(beta,x) where beta is a vector of coefficients
and x is a data frame (think of it as a matrix). I want to optimize the
function myFunction() by ONLY changing beta, i.e. x stays constant, with 4
constraints. I have the following code (with a separate source file for the
function):
rm(list=ls())
source('mySourceFile')
2006 Nov 13
2
Embedded carriage returns in text document
Colleagues,
I am using R 2.4.0 on both a Mac (10.4.8) and Linux (RedHat 9). To
read data from an Excel spreadsheet, I do "save as" in Excel, then
select the "Text (tab-delimited)" format. The resulting file uses a
tab separator and I can usually read the file using read.delim.
Sometimes, the header row contains embedded carriage returns. When I
view the file,
2011 Jun 10
4
running R commands asynchronously
I am interested in running R commands asynchronously.
My first choice is in the same R session that I am currently in.
Here, the goal would be to run something like
RunAsynchSameSession(myfunction(), "outputname.rda")
Once RunAsynchSameSession had started myfunction(),
RunAsynchSameSession would complete immediately. myfunction would
keep going. It is OK if execution of the
2011 Feb 17
1
calling pairs of variables into a function
Hi,
I have imported three text files into R using read.table. Their variables
are called d, e and f.
I want to run a function on all the possible combinations of these three
files. The only way I know how to do that is like this:
bigfunction(d,e)
bigfunction(d,f)
bigfunction(e,d)
bigfunction(e,f)
bigfunction(f,e)
bigfunction(f,d)
Is there an easier way? I will have five files later on, so
2009 Sep 29
3
Deleting a column in a dataframe by name
Colleagues,
Hopefully a simple problem: I want to delete a column with a known
name from a dataframe. I could write:
FRAME <- FRAME[, names(FRAME) != NAMETODELETE]
or
FRAME <- FRAME[, !names(FRAME) %in% c(NAME1, NAME2, ETC)]
Is there some simpler means to accomplish this?
Dennis
Dennis Fisher MD
P < (The "P Less Than" Company)
Phone: 1-866-PLessThan (1-866-753-7784)
2007 Sep 04
2
Recursive concatenation
Colleagues,
I want to create the following array:
"A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"
I recall that there is a trick using "c" or "paste" permitting me to
form all combinations of c("A", "B", "C") and 1:3. But, I can't
recall the
2008 Apr 11
3
strsplit and sapply
Colleagues,
I have some text:
TEXT <- c("a", "bb;ccc", "dddd;eeeee;ffffff")
I want to retrieve the portion of each element before the first
semicolon. I can split each element using strsplit:
SPLIT <- strsplit(TEXT, ";")
This yields:
> SPLIT
[[1]]
[1] "a"
[[2]]
[1] "bb" "ccc"
[[3]]
[1] "dddd"
2004 Apr 13
1
Execute function at startup
It would be convenient to have something like
Rgui runfist="myfunction()"
in Windows.
The reason:
AFAIK Rgui does not accept piped input
(RGui < myfile.R does not seem to work).
A solution could be to put a few fuctions in Rprofile and then
give the name for one of these functions to be executed at startup as
a command line parameter to Rgui.
Can something like this be done?
--
2004 Apr 13
1
Execute function at startup
It would be convenient to have something like
Rgui runfist="myfunction()"
in Windows.
The reason:
AFAIK Rgui does not accept piped input
(RGui < myfile.R does not seem to work).
A solution could be to put a few fuctions in Rprofile and then
give the name for one of these functions to be executed at startup as
a command line parameter to Rgui.
Can something like this be done?
--
2005 Oct 18
6
Subsetting a list
Colleagues,
I have created a list in the following manner:
TEST <- list(c("A1", "A2"), c("B1", "B2"), c("C1", "C2"))
I now want to delete one element from the list, e.g., the third. The
command
TEST[[3]]
yields (as expected):
[1] "C1" "C2"
The command
TEST[[-3]]
yields:
Error:
2008 Dec 15
3
opening a PDF document
Colleagues,
I am interesting in opening a PDF document via the command line from
both Windows, OS X, and Linux ( R version 2.8.0). I found a command
openPDF in Biobase. However, I would rather execute the command
myself. For example, in OS X:
> system("open filename.pdf")
is successful.
Is there a comparable command line command for Windows or Linux?
Dennis
Dennis Fisher
2011 Mar 04
1
Environment variable PATH in Windows
Colleagues,
I am trying to understand how R (2.12.1) obtains the PATH environment variable in Windows (7 or Vista). Startup {base} directs one to:
"R_ENVIRON" -- which equals "" in my systems
R_HOME/etc/Renviron.site -- which does not exist
Next, it directs to:
R_HOME/etc/Rprofile.site -- which also does not exist (the expected behavior in a "factory-fresh"
2006 Oct 21
2
Filling in a series
Colleagues
After reading in some clinical data, I discovered that the subject ID
column contains entries only for the first record for each
individual; subsequent rows are recorded as NA. For example:
> 1
> NA
> NA
> NA
> NA
> 2
> NA
> NA
> NA
> NA
> 3
> NA
> NA
> ...
I can think of various approaches to replace the NA values with
appropriate
2007 Aug 03
3
Sourcing commands but delaying their execution
Colleagues:
I have encountered the following situation:
SERIES OF COMMANDS
source("File1")
MORE COMMANDS
source("File2")
Optimally, I would like File1 and File2 to be merged into a single
file (FileMerged). However, if I wrote the following:
SERIES OF COMMANDS
source("FileMerged")
MORE COMMANDS
I encounter an error: the File2 portion of FileMerged
2009 Jan 30
3
identifying what labels have been created in a plot
Colleagues
R 2.8.0; OS X, Vista, Ubuntu Linux
In some instances, when I create a graphic using plot(XVAR, YVAR), it
would be valuable to know the values that R will display on the y-axis
(e.g., if the range of data is 0-70, it might display 0, 10, 30, 50,
70). Is there a simple means to access these values?
Also, in some instances, additional ticks appear between the displayed
values
2010 Feb 12
1
Identifying special characters in a text file
Colleagues
R 2.10.1 on a Mac
I read in textfiles using readLines, then I process those files, then I use R to execute another program. Occasionally those files contain characters other than letter / numbers / routine punctuation marks. For example, a bullet (option-8 on a Mac) triggers the problem.
Although R can read and process those characters, the other program cannot so I would like to