similar to: exists() and functions

Displaying 20 results from an estimated 10000 matches similar to: "exists() and functions"

2011 Nov 21
3
How do I query "..." in a function call?
This is probably a very noobish question, but if I want to create a function that allows an undetermined number of, say, numeric vectors to be fed to it, I would use: myfunction = function(...) { # Do something } Right? If so, how do I a) count the number of vectors "fed" to the function, and b) how do I treat those vectors as variables, e.g. for the call:
2012 Oct 17
2
Completely ignoring an error in a function...
The code base is a bit too complicated to paste in here, but the gist of my question is this: given I have a function myfunction <- function(x) { # Do something A # Do something B # Do something C } Say "#Do something B" returns this error: Error in cat(list(...), file, sep, fill, labels, append) : argument 2 (type 'list') cannot be handled by 'cat' A standard
2010 Jan 28
2
Data frame of different sized lists in a function call
I'm hoping to get some "best practice" feedback for constructing a function call which takes an undefined set of DIFFERENT length vectors -- e.g. say we have two lists: list1=c(1:10) list2=c(2:4) lists = data.frame(list1,list2) coerces those two to be the same length (recycling list2 to fill in the missing rows) -- what is a quick way of having each of those lists retain their
2009 Aug 27
19
Best R text editors?
Quick informal poll: what is everyone's favorite text editor for working with R? I'd like to hear from people who are using editors that have some level of direct R interface (e.g. Tinn-R, Komodo+SciViews). Thanks! --j -- Jonathan A. Greenberg, PhD Postdoctoral Scholar Center for Spatial Technologies and Remote Sensing (CSTARS) University of California, Davis One Shields Avenue The
2011 Aug 23
5
Easier ways to create .Rd files?
R-helpers: Are there any ways to auto-generate R-friendly (e.g. will pass a compilation check) .Rd files given a set of .R code? How about GUIs that help properly format the .Rd files? Thanks! I want a basic set of .Rd files that I can update as I go, but as with most things my documentation typically lags behind my coding by a few days. --j -- Jonathan A. Greenberg, PhD Assistant Project
2004 Feb 19
4
1024GB max memory on R for Windows XP?
I have 2GB installed on my windows XP box running R 1.9.0, and after performing a prune.tree(intree,newdata), I get an out of memory error within R, but it says the maximum allowed is 1024gb (1/2 of what I have!) Can R not use more than 1GB on an XP box? I noticed I had ~600mb left over after R conked out, so clearly I had more memory... What about virtual memory? --j -- Jonathan Greenberg
2010 May 10
3
dbSendQuery with R variables
Rhelpers: I'd like to modify this RSQLite statement: rs_stations<-dbSendQuery(con_stations, "select * from stations") so that stations is actually an R variable, e.g.: stations=c("stationA","stationB") How would I modify the above statement to query from stations[[1]] (aka "stationA")? --j
2005 Aug 17
2
About R variable references
Hello Group, I could use an advice on how SEXP handles work. My aim is to implement a system where I initially set a few global variables that are used for communication between C and R code. Then I do some work with R code and periodically call a function of my own that will update the system state. Such a design is useful for many purposes (for GUIs to name one). I am not entirely sure that R
2009 Nov 02
2
"Safe" way to automatically install required packages...
R-helpers: I'm working on an r-package that I want to make as easy-to-use as possible for a novice R-user, which includes automatically installing required packages. I, myself, am a novice R-packager, so the solution I came up with was to embed: print("Loading required packages...") if (!require("reshape")) { install.packages("reshape") } if
2010 Jun 15
2
Fastest way to merge matrix columns into a comma delimited string?
Folks: Say I have a matrix: test=matrix(c(1,2,3),nrow=10,ncol=3) I would like to have an output character vector where each line is row's values delimited by commas, e.g.: "1,2,3" "2,3,1" "3,1,2" ... "1,2,3" What is the fastest way of doing this? I can paste() row-by-row but this seems an inefficient approach to doing this. Thanks! I'm not
2004 Feb 13
2
Readbin and file position
I have a binary file which is an image with multiple bands, arranged in BSQ format such that R, B and G are all N x M sized matrices (corresponding to Red, Blue and Green colors respectively). The BSQ file arranges the data as [R, B, G], so to access the B matrix, I have to read forward N x M + 1 number of samples. Is there a fast way to define a variable as the B matrix exclusively (e.g. Can I
2002 Mar 17
2
Running R on MacOS X
Hi there -- I downloaded the MacOS X binaries of R and followed the instructions on installing it, and when I go to perform a tree function, I get the error "Error: couldn't find function "tree"". Do I need to somehow preload the function? If so, how do I do that? Also, update.packages() works for some packages, but not all -- it often fails in the compilation. I have
2010 Sep 22
3
Passing a function as a parameter...
R-helpers: If I want to pass a character name of a function TO a function, and then have that function executed, how would I do this? I want an arbitrary version of the following, where any function can be used (e.g. I don't want the if-then statement here): apply_some_function <- function(data,function_name) { if(function_name=="mean") { return(mean(data)) }
2009 Oct 26
2
R CMD check: Error in .C
Function/file names are hypothetical. Say I have written myfunction.R, which calls myfunction.c via .C("myfunction", ...). I've compiled successfully myfunction.c via R CMD SHLIB myfunction.c in the terminal. Then, in the R console: dyn.load("myfunction.so") source("myfunction.R") test <- myfunction() # works fine So everything is in order, myfunction works
2009 Oct 20
2
Problem using the source-function within R-functions
Dear R community, You may have the solution to how to construct a function using the function "source()" to build the function; i.e. myfunction <- function(...){ source('file1.r') source('file2.r') } After compiling and installing the "myfunction" in R, then calling the "myfunction" gives an error because the content of 'file1.r' and
2012 Nov 23
1
Adding a function with default parameters into the Rcmdr menu
Hi everyone, I made some tests with Rcmdr, to add a function with default parameters : For example (very simple): myfunction<-function(var="314"){ print("hello") print(var) } if I run myfunction() directly i see : > myfunction() [1] "hello" [1] "314" it's ok. But if i edit de Rcmdr-menu.txt (in
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')
2009 Mar 18
2
How do I set the Windows temporary directory in R?
I'm trying to redirect where temporary files go under R to D:\temp\somerandomname from its default (C:\Documents and Settings\username\Temp\somerandomname) -- how do I go about doing this? --j -- Jonathan A. Greenberg, PhD Postdoctoral Scholar Center for Spatial Technologies and Remote Sensing (CSTARS) University of California, Davis One Shields Avenue The Barn, Room 250N Davis, CA 95616
2002 Nov 09
2
Nonlinear regression and categories
Hi there: I'm trying to run a large number of nonlinear regressions on a time series dataset, where the data will be formatted something to the effect of: ObservationID,time,dependentvar I'll have a number of time and dependentvars for each observation, and I want to apply a nonlinear regression to one ObservationID at a time, and I want to have a dataset that is the parameter
2004 Feb 12
1
Importing BSQ/BIP/BIL files into R
I was hoping I could get some help with an import question. I work with remote sensing imagery which commonly comes in binary form in various interleaving formats (byte interleaved by line, by pixel, etc..). These files are 2d spatial x B bands in size, and I want to be able to extract the band values from various pixels (so each line of data into R would be one pixel x B bands). What's the