[R] R Script Help!

2011-06-21 Thread geo...@leadbetter.cc
I have written a script in an R text file that i can run through a terminal
window. My script though contains lots of code to interpret my input
arguments, which are then put into an SQL query to get the data I want to
plot some graphs. The script works, but there must be an easier way to do
what I want using maybe Rscript or something else but I can't seem to find
it! Any help would be much appreciated.

Thanks,
George

--
View this message in context: 
http://r.789695.n4.nabble.com/R-Script-Help-tp3614065p3614065.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R Script Help!

2011-06-21 Thread Sarah Goslee
Hi George,

On Tue, Jun 21, 2011 at 9:33 AM, geo...@leadbetter.cc
geo...@leadbetter.cc wrote:
 I have written a script in an R text file that i can run through a terminal
 window. My script though contains lots of code to interpret my input
 arguments, which are then put into an SQL query to get the data I want to
 plot some graphs. The script works, but there must be an easier way to do
 what I want using maybe Rscript or something else but I can't seem to find
 it! Any help would be much appreciated.

There's almost certainly an easier way, or several, but we don't know
what you're doing, or what you want.

You've written a script. It has code in it. It works.

And?

Obviously somehow you're running it. We don't know how.

Something is more complicated than you'd like. We don't know what.

You've looked for more ideas. We don't know what about.

Sarah

 Thanks,
 George


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R Script Help!

2011-06-21 Thread Sarah Goslee
Hi,

So is your actual question about how to prompt for user input, rather
than anything about the SQL extraction or graphing?

I think I would write the R code as a function that takes the four
values as arguments. That's not  the same as prompting the user, but
more flexible and more R-ish.

You could also try readline() for getting input. If you search the
mailing list archives, that question comes up fairly regularly.

I've taken the liberty of copying this to the R-help list in case
someone else has more suggestions. You need to choose reply all and
not just reply for that to happen.

Sarah

On Tue, Jun 21, 2011 at 6:19 PM,  geo...@leadbetter.cc wrote:
 Hi Sarah,

 Thanks for your response. I understand now my question is phrased very
 poorly. I think this is what I should have said.

 1) My problem - I have a database in SQL and access to R. I want to write to
 write a script to generate a graph using information from the SQL database.
 What I really want is the user of the script to be prompted for 4 pieces of
 information: a start date, a finish date, and 2 product codes related to the
 datbase. I want to take these 4 inputs, which define the data I need from
 the database and use this data to generate the graph.

 2) what i currently and doing is the following. I have opened an R text file
 and used the commandArgs function to generate my query and produce my graph.
 This has to be run through a terminal window. I'm using a Mac, so I type
 into the terminal window, Rscript filename.R --from 2011-05-01 --to
 2011-06-01  etc. So the user isn't prompted for the arguments you have to
 know them. I've made it so that if you just type Rscript filename.R into the
 terminal and execute then it returns a help message which shows you what to
 do.

 These args are then manipulated in this text file so that they can be put
 into an SQLquery embedded in the text file, the data I want is then
 extracted and from this the graphs are generated.

 I'm not sure my use of the term R text file is correct. What I refer to as
 an R text file is what you get when you click the blank page icon at the
 presented at the top of the screen on an R console window.

 The way I have gone about solving my problem seems unnecessarily long winded
 to me and I know there are significantly easier ways of going about similar
 tasks in Matlab (which I no longer have access to). I was hoping you could
 point me in the right direction.

 Many thanks,
 George Leadbetter

 Quoting Sarah Goslee sarah.gos...@gmail.com:

 Hi George,

 On Tue, Jun 21, 2011 at 9:33 AM, geo...@leadbetter.cc
 geo...@leadbetter.cc wrote:

 I have written a script in an R text file that i can run through a
 terminal
 window. My script though contains lots of code to interpret my input
 arguments, which are then put into an SQL query to get the data I want to
 plot some graphs. The script works, but there must be an easier way to do
 what I want using maybe Rscript or something else but I can't seem to
 find
 it! Any help would be much appreciated.

 There's almost certainly an easier way, or several, but we don't know
 what you're doing, or what you want.

 You've written a script. It has code in it. It works.

 And?

 Obviously somehow you're running it. We don't know how.

 Something is more complicated than you'd like. We don't know what.

 You've looked for more ideas. We don't know what about.

 Sarah

 Thanks,
 George


 --
 Sarah Goslee
 http://www.functionaldiversity.org






__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] R script HELP!

2011-02-18 Thread whizevans

The following is my R script which I am struggling with to assess ICESat
data..perhaps it is the ID_min or ID_max that is wrong? I don't know, any
help would be greatly appreciated :(


# OPTIONS - CHANGE THESE VARIABLES IF NEEDED\par
##\par
\par
icesatfile - 

'C:/Users/Whiz/My_Documents/Year3/GY3072/ICESat_GLAS/IDLreadGLASWF/out_wf_GLA01_09030918_r5947_031_L2E.dat'\par
\par
plotdir - 'C:/Users/Whiz/My_Documents/Year3/GY3072/ICESat_GLAS/PLOT'\par
\par
\par
\par
ID_min - 976834501  290018099.3145 1000 #231741042 # specify range of
waveforms to be plotted, -1 means all\par
ID_max - 976834506  290018101.2895 1000 @@@note only
one ID used @@@\par
\par
\par
\par
noise - 0.05 # values below NOISE will be disregarded in the waveform
fitting\par
sdthres - 0.02 # threshold for a standard deviation of volt measurements
indicating the presence of a signal\par
\par
fit_waveform_model - TRUE # set to TRUE this activates the Gaussian
waveform model fitting and plotting\par
#fit_waveform_select - c(976834501  290018099.3145 1000)  # gives the
Unique ID for which the model fitting will 

be activated\par
\par
#\par
# END OF OPTIONS\par
-- 
View this message in context: 
http://r.789695.n4.nabble.com/R-script-HELP-tp3312644p3312644.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R script HELP!

2011-02-18 Thread Jonathan P Daily
It looks to me like when you assign ID_min and ID_max that you want them 
to be vectors. In R, this is accomplished by ?c.

Example:
ID_min - c(976834501,  290018099.3145, 1000)

--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 02/18/2011 08:21:36 AM:

 [image removed] 
 
 [R] R script HELP!
 
 whizevans 
 
 to:
 
 r-help
 
 02/18/2011 08:49 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 
 The following is my R script which I am struggling with to assess ICESat
 data..perhaps it is the ID_min or ID_max that is wrong? I don't know, 
any
 help would be greatly appreciated :(
 
 
 # OPTIONS - CHANGE THESE VARIABLES IF NEEDED\par
 
##\par
 \par
 icesatfile - 
 
 'C:/Users/Whiz/My_Documents/Year3/GY3072/ICESat_GLAS/IDLreadGLASWF/
 out_wf_GLA01_09030918_r5947_031_L2E.dat'\par
 \par
 plotdir - 
'C:/Users/Whiz/My_Documents/Year3/GY3072/ICESat_GLAS/PLOT'\par
 \par
 \par
 \par
 ID_min - 976834501  290018099.3145 1000 #231741042 # specify range of
 waveforms to be plotted, -1 means all\par
 ID_max - 976834506  290018101.2895 1000 @@@note 
only
 one ID used @@@\par
 \par
 \par
 \par
 noise - 0.05 # values below NOISE will be disregarded in the waveform
 fitting\par
 sdthres - 0.02 # threshold for a standard deviation of volt 
measurements
 indicating the presence of a signal\par
 \par
 fit_waveform_model - TRUE # set to TRUE this activates the Gaussian
 waveform model fitting and plotting\par
 #fit_waveform_select - c(976834501  290018099.3145 1000)  # gives the
 Unique ID for which the model fitting will 
 
 be activated\par
 \par
 
#\par
 # END OF OPTIONS\par
 -- 
 View this message in context: http://r.789695.n4.nabble.com/R-
 script-HELP-tp3312644p3312644.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R script HELP!

2011-02-18 Thread whizevans

OK thanks Jonathon, I will have a go.
Is the plotdir file technically my output file? Or what is this otherwise?

Also, having never used R script before, is it not very good at reading
data, may I have to alter my input file in excel first?
Thanks


-- 
View this message in context: 
http://r.789695.n4.nabble.com/R-script-HELP-tp3312644p3312898.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R script HELP!

2011-02-18 Thread Jonathan P Daily
Well, this script only shows the option settings, so I assumed that the 
string being used as your infile was formatted for R. As for how it will 
have to look for R to read it in, there are many ways to do this - I would 
start by reading R Data Import/Export that ships with every copy of R. 
As for scripts and their default writing methods AFAIR Rscript writes to 
stdout, though if you want it to save your modified data in some other 
format than a text dump, look at the various methods of exporting data... 
again in the aforementioned R Data Import/Export.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 02/18/2011 10:29:55 AM:

 [image removed] 
 
 Re: [R] R script HELP!
 
 whizevans 
 
 to:
 
 r-help
 
 02/18/2011 11:06 AM
 
 Sent by:
 
 r-help-boun...@r-project.org
 
 
 OK thanks Jonathon, I will have a go.
 Is the plotdir file technically my output file? Or what is this 
otherwise?
 
 Also, having never used R script before, is it not very good at reading
 data, may I have to alter my input file in excel first?
 Thanks
 
 
 -- 
 View this message in context: http://r.789695.n4.nabble.com/R-
 script-HELP-tp3312644p3312898.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] R script help needed for RFC 2104 HMAC algorithm

2010-10-19 Thread Larry D'Agostino
I'm trying to create an R script that will execute the HMAC algorithm for
key-hashing messages.  My hope is to use this script for some web
authentication via R.

The algorithm is found at http://www.ietf.org/rfc/rfc2104.txt

Here is some example code that I have done that does not work for HMAC-MD5.
I'm a big confused by the algorithm since I don't have a very good working
knowledge of digests or hex strings.   I would really appreciate some
assistance if anyone can take a look at this code and offer advice.

The RFC website does offer C code to execute the HMAC algorithm but I am not
a C expert.


 HMAC Code #

library(digest)

## hex to binary

hexdat - replicate(10, paste(format.hexmode(sample(16,4)-1),collapse=''))
bin - apply(outer(0:15,3:0,function(x,y) x%/%(2^y)%%2),1,paste,collapse=)
names(bin) - format.hexmode( 0:15 )

## test
## cbind( hexdat, sapply( strsplit(hexdat,'') , function(x) paste( bin[x],
collapse='' ) ) )


## binary to hex

hex - names(bin)
names(hex) - bin



 Test HMAC_MD5 

### B=64
### L=16

#key - 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
##key_len = 16 bytes
data - Hi There
##data_len = 8 bytes

## digest =  0x9294727a3638bb1c13f48ef8158bfc9d

ipad - rep(36,64)
opad - rep(5c,64)


k - rep(0b, 16)
zeros - rep(00,48)
K - c(k, zeros)

K_bin - cbind(K, sapply( strsplit(K,'') , function(x) paste( bin[x],
collapse='' ) ) )
ipad_bin - cbind(ipad, sapply( strsplit(ipad,'') , function(x) paste(
bin[x], collapse='' ) ) )

#cbind(K_bin, sapply( strsplit(K_bin[,2],'') , as.numeric) )

K_binnum - sapply( strsplit(K_bin[,2],'') , as.numeric)
ipad_binnum - sapply( strsplit(ipad_bin[,2],'') , as.numeric)


InnerXOR - as.numeric(xor(K_binnum, ipad_binnum))
InnerXOR - matrix(InnerXOR, 4, 128)
InnerXOR - t(InnerXOR)
InnerXORbin - apply(InnerXOR, 1, paste, collapse='')

InnerXORhex - cbind(InnerXORbin, sapply(InnerXORbin, function(x)
paste(hex[x], collapse='') ))
InnerXORhex - t(matrix(InnerXORhex[,2],2,64))
InnerXORhex - apply(InnerXORhex, 1, paste, collapse='')

dataHex - charToRaw(data)

cmb - c(InnerXORhex, dataHex)
cmb - paste(cmb, collapse='')

InnerHash - digest(cmb, algo=md5)

opad_bin - cbind(opad, sapply( strsplit(opad,'') , function(x) paste(
bin[x], collapse='' ) ) )

opad_binnum - sapply( strsplit(opad_bin[,2],'') , as.numeric)

OuterXOR - as.numeric(xor(K_binnum, opad_binnum))
OuterXOR - matrix(OuterXOR, 4, 128)
OuterXOR - t(OuterXOR)
OuterXORbin - apply(OuterXOR, 1, paste, collapse='')

OuterXORhex - cbind(OuterXORbin, sapply(OuterXORbin, function(x)
paste(hex[x], collapse='') ))
OuterXORhex - t(matrix(OuterXORhex[,2],2,64))
OuterXORhex - apply(OuterXORhex, 1, paste, collapse='')
OuterXORhex - paste(OuterXORhex, collapse='')

outercmb - paste(OuterXORhex, InnerHash, sep=)
HMAC_MD5 - digest(outercmb, algo=md5) should equal the digest
example above

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.