Re: [R] XML to CSV

2017-01-25 Thread Franzini, Gabriele [Nervianoms]
They are attributes, not nodes so, if I understood the question:

"//DischargeMedication/Medication/@MedAdmin"
"//DischargeMedication/Medication/@MedID"

should do.
HTH, 
Gabriele


From: Andrew Lachance [mailto:alach...@bates.edu] 
Sent: Wednesday, January 25, 2017 3:12 PM
To: Franzini, Gabriele [Nervianoms]
Cc: r-help@r-project.org
Subject: Re: [R] XML to CSV

Hello all,

Thank you for the extremely helpful information. As a follow up, some of the 
nested elements are of the form below:
-
    
    

I've been having trouble extracting this information and was wondering if 
anyone had any suggestions.

Thank you,
Andrew

On Thu, Jan 5, 2017 at 7:39 AM, Franzini, Gabriele [Nervianoms] 
<gabriele.franz...@nervianoms.com> wrote:
Hello Andrew,

as you are "clean slate" anyway in handling XML files, you could take a look to 
XSLT processing -- also an off-topic area.
There are free tools available around, and many examples of "XML to CSV XSLT" 
on StackOverflow.

HTH,
Gabriele

-Original Message-

On January 4, 2017 12:45:08 PM PST, Ben Tupper <btup...@bigelow.org> wrote:
>Hi,
>
>You should keep replies on the list - you never know when someone will
>swoop in with the right answer to make your life easier.
>
>Below is a simple example that uses xpath syntax to identify (and in
>this case retrieve) children that match your xpath expression.  xpath
>epxressions are sort of like /a/directory/structure/description so you
>can visualize elements of XML like nested folders or subdirectories.
>
>Hopefully this will get you started.  A lot more on xpath here
>http://www.w3schools.com/xml/xml_xpath.asp  There are other extraction
>tools in xml2 - just type ?xml2 at the command prompt to see more.
>
>Since you have more deeply nested elements you'll need to play with
>this a bit first.
>
>library(xml2)
>uri = 'http://www.w3schools.com/xml/simple.xml'
>x = read_xml(uri)
>
>name_nodes = xml_find_all(x, "//name")
>name = xml_text(name_nodes)
>
>price_nodes = xml_find_all(x, "//price")
>price = xml_text(price_nodes)
>
>calories_nodes = xml_find_all(x, "//calories")
>calories = xml_double(calories_nodes)
>
>X = data.frame(name, price, calories, stringsAsFactors = FALSE)
>write.csv(X, file = 'foo.csv')
>
>Cheers,
>Ben
>
>> On Jan 4, 2017, at 2:13 PM, Andrew Lachance <alach...@bates.edu>
>wrote:
>>
>> Hello Ben,
>>
>> Thank you for the advice. I am extremely new to any sort of coding so
>I have learned a lot already. Essentially, I was given an XML file and
>was told to convert all of it to a csv so that it could be uploaded
>into a database. Unfortunately the information I am working with is
>medical information and can't really share it. I initially tried to
>convert it using online programs, however that ended up with a large
>amount of blank spaces that wasn't useful for uploading into the
>database.
>>
>> So essentially, my goal is to parse all the data in the XML to a
>coherent, succinct CSV that could be uploaded. In the document, there
>are 361 patient files with 13 subcategories for each patient which
>further branches off to around 150 categories total. Since I am so new,
>I have been having a hard time seeing the bigger picture or knowing if
>there are any intermediary steps that will prevent all the blank spaces
>that the online conversion programs created.
>>
>> I will look through the information on the xml2 package. Any advice
>or recommendations would be greatly appreciated as I have felt fairly
>stuck. Once again, thank you very much for your help.
>>
>> Best,
>> Andrew
>>
>> On Tue, Jan 3, 2017 at 2:29 PM, Ben Tupper <btup...@bigelow.org
><mailto:btup...@bigelow.org>> wrote:
>> Hi,
>>
>> It's hard to know what to advise - much depends upon the XML data you
>have and what you want to extract from it. Without knowing about those
>two things there is little anyone could do to help.  Can you post to
>the internet a to example data and provide the link here?  Then state
>explicitly what you want to have in hand at the end.
>>
>> If you are just starting out I suggest that you try xml2 package (
>https://cran.r-project.org/web/packages/xml2/
><https://cran.r-project.org/web/packages/xml2/> ) rather than XML
>package ( https://cran.r-project.org/web/packages/XML/
><https://cran.r-project.org/web/packages/XML/> ). I have been using it
>much more since the authors added the ability to create xml nodes
>(rather than just extracting data from existing xml nodes).
>>
>> Cheers,
>> Ben
>>
>> P.S.  Hello to my niece Olivia S on the Bates EMS team.
>>
>>
>> 

Re: [R] XML to CSV

2017-01-05 Thread Franzini, Gabriele [Nervianoms]
Hello Andrew,

as you are "clean slate" anyway in handling XML files, you could take a look to 
XSLT processing -- also an off-topic area. 
There are free tools available around, and many examples of "XML to CSV XSLT" 
on StackOverflow.

HTH,
Gabriele

-Original Message-

On January 4, 2017 12:45:08 PM PST, Ben Tupper  wrote:
>Hi,
>
>You should keep replies on the list - you never know when someone will
>swoop in with the right answer to make your life easier.
>
>Below is a simple example that uses xpath syntax to identify (and in
>this case retrieve) children that match your xpath expression.  xpath
>epxressions are sort of like /a/directory/structure/description so you
>can visualize elements of XML like nested folders or subdirectories.
>
>Hopefully this will get you started.  A lot more on xpath here
>http://www.w3schools.com/xml/xml_xpath.asp  There are other extraction
>tools in xml2 - just type ?xml2 at the command prompt to see more.
>
>Since you have more deeply nested elements you'll need to play with
>this a bit first.
>
>library(xml2)
>uri = 'http://www.w3schools.com/xml/simple.xml'
>x = read_xml(uri)
>
>name_nodes = xml_find_all(x, "//name")
>name = xml_text(name_nodes)
>
>price_nodes = xml_find_all(x, "//price")
>price = xml_text(price_nodes)
>
>calories_nodes = xml_find_all(x, "//calories")
>calories = xml_double(calories_nodes)
>
>X = data.frame(name, price, calories, stringsAsFactors = FALSE)
>write.csv(X, file = 'foo.csv')
>
>Cheers,
>Ben
>
>> On Jan 4, 2017, at 2:13 PM, Andrew Lachance 
>wrote:
>> 
>> Hello Ben,
>> 
>> Thank you for the advice. I am extremely new to any sort of coding so
>I have learned a lot already. Essentially, I was given an XML file and
>was told to convert all of it to a csv so that it could be uploaded
>into a database. Unfortunately the information I am working with is
>medical information and can't really share it. I initially tried to
>convert it using online programs, however that ended up with a large
>amount of blank spaces that wasn't useful for uploading into the
>database.
>> 
>> So essentially, my goal is to parse all the data in the XML to a
>coherent, succinct CSV that could be uploaded. In the document, there
>are 361 patient files with 13 subcategories for each patient which
>further branches off to around 150 categories total. Since I am so new,
>I have been having a hard time seeing the bigger picture or knowing if
>there are any intermediary steps that will prevent all the blank spaces
>that the online conversion programs created.
>> 
>> I will look through the information on the xml2 package. Any advice
>or recommendations would be greatly appreciated as I have felt fairly
>stuck. Once again, thank you very much for your help.
>> 
>> Best,
>> Andrew
>> 
>> On Tue, Jan 3, 2017 at 2:29 PM, Ben Tupper > wrote:
>> Hi,
>> 
>> It's hard to know what to advise - much depends upon the XML data you
>have and what you want to extract from it. Without knowing about those
>two things there is little anyone could do to help.  Can you post to
>the internet a to example data and provide the link here?  Then state
>explicitly what you want to have in hand at the end.
>> 
>> If you are just starting out I suggest that you try xml2 package (
>https://cran.r-project.org/web/packages/xml2/
> ) rather than XML
>package ( https://cran.r-project.org/web/packages/XML/
> ). I have been using it
>much more since the authors added the ability to create xml nodes
>(rather than just extracting data from existing xml nodes).
>> 
>> Cheers,
>> Ben
>> 
>> P.S.  Hello to my niece Olivia S on the Bates EMS team.
>> 
>> 
>> > On Jan 3, 2017, at 11:27 AM, Andrew Lachance > wrote:
>> >
>> > up votdown votefavorite
>> >
>>
>> >
>> > I am completely new to R and have tried to use several functions
>within the
>> > xml packages to convert an XML to a csv and have had little
>success. Since
>> > I am so new, I am not sure what the necessary steps are to complete
>this
>> > conversion without a lot of NA.
>> >
>> > --
>> > Andrew D. Lachance
>> > Chief of Service, Bates Emergency Medical Service
>> > Residence Coordinator, Hopkins House
>> > Bates College Class of 2017
>> > alach...@bates.edu  >
>> > (207) 620-4854
>> >
>> >   [[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@r-project.org  mailing list --
>To UNSUBSCRIBE and more, see
>> > 

Re: [R] Presentation tables in R (knitr)

2014-11-26 Thread Franzini, Gabriele [Nervianoms]

I found also knitr + html + the ReporteRs package a good combination,
and less intimidating than Latex. Have a look at their FlexTable tool.

HTH,
Gabriele  


-Original Message-
From: Tom Wright [mailto:t...@maladmin.com] 
Sent: Tuesday, November 25, 2014 9:12 PM
To: r-help@r-project.org
Subject: [R] Presentation tables in R (knitr)

Hi,
This problem has me stumped so I thought I'd ask the experts. I'm trying
to create a pretty summary table of some data (which patients have had
what tests at what times). Ideally I'd like to knitr this into a pretty
PDF for presentation.
If anyone has pointers I'll be grateful.

require(tables)
require(reshape2)

data-data.frame('ID'=paste0('pat',c(rep(1,8),rep(2,8))),
 'Time'=c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4),
 'Eye'=rep(c('OS','OS','OD','OD'),4),
 'Measure'=rep(c('Height','Weight'),8))

tabular(Measure~factor(ID)*factor(Time)*factor(Eye),data)
#All levels of Time are repeated for all IDs, I'd prefer to just show
the relevant times.

tabular(Measure~factor(ID)*Time*factor(Eye),data)
#Time is getting collapsed by ID

data$value=1
dcast(data,Measure~ID+Time+Eye)
#close but not very pretty

__
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] converting XML document to table or dataframe

2013-01-31 Thread Franzini, Gabriele [Nervianoms]
Hello,

R is good at handling XML, but in this case I would rather do the first
step with an XSLT transformation, e.g. with Saxon, possibly to a CSV
file.

HTH,
Gabriele


-Original Message-
From: Anika Masters [mailto:anika.mast...@gmail.com] 
Sent: Tuesday, January 29, 2013 3:01 AM
To: r-help@r-project.org
Subject: [R] converting XML document to table or dataframe

I am a relatively new user to R, and I am trying to learn more about
converting data in an XML document into 2-dimensional format such as a
table or array.  I might eventually wish to export this data into a
relational database such as SQL, and/or to work with this data within
the R package.

My sample XML document is located at 
http://www.sec.gov/Archives/edgar/data/743988/000124636013000561/form.xm
l

I have successfully import the XML document and then converted the XML
document to a list.

I am stuck trying to convert the document into a 2-dimenional table
or dataframe.

What is a good way to convert the XML document to a 2-dimensional
table or data.frame?  Ideally, I'd like a table with 1 row for each XML
document, and unique fieldnames.  If fieldnames repeat, I'd like the
names to be numbered sequentially

e.g.
$nonDerivativeTable$nonDerivativeTransaction$transactionAmounts$transact
ionPricePerShare$value_1
$nonDerivativeTable$nonDerivativeTransaction$transactionAmounts$transact
ionPricePerShare$value_2
$nonDerivativeTable$nonDerivativeTransaction$transactionAmounts$transact
ionPricePerShare$value_3

etc




myxml = xmlParse(
http://www.sec.gov/Archives/edgar/data/743988/000124636013000561/form.xm
l)
mylist - xmlToList(mydoc)
mydf - xmlToDataFrame(mydoc)
mydf2 - data.frame(mylist)
mytable - as.table(mylist)
mydf2 - data.frame(mydoc)
mytable - as.table(mydoc)

[[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.


Re: [R] Create a Data Frame from an XML

2013-01-24 Thread Franzini, Gabriele [Nervianoms]
Hello Adam,
I had a similar problem with a big dataframe, and building an xmlTree in
the clean way was extremely slow; so i resorted to manual method. Not
tested, but if your dataframe is my_df, then something like the
following should do:

buildEntry - function(x) {
cat(paste('z:row BRAND=', x[1],
 ' NUM=', x[2],
 ' YEAR=', x[3],
 ' VALUE=', x[4],
 '/\n', sep=))
}

sink(paste('my_file.xml', sep=))

cat ('?xml version=1.0 encoding=ISO-8859-1?\n')
cat ('data xmlns=uri://localhost/z\n')
 
# invisible avoids returning a NULL in the file
invisible(apply(my_df, 1, buildEntry))
cat (/data )
sink()

And it took very little time.

HTH,
Gabriele


-Original Message-
From: Adam Gabbert [mailto:adamjgabb...@gmail.com] 
Sent: Wednesday, January 23, 2013 5:36 PM
To: Duncan Temple Lang; btup...@bigelow.org
Cc: r-help@r-project.org
Subject: Re: [R] Create a Data Frame from an XML

Hello Gentlemen,

I mistakenly sent the message twice, because the first time I didn't
receive a notification message so I was unsure if it went through
properly.

Your solutions worked great. Thank you!  I felt like I was fairly close
just couldn't quite get the final step.

Now, I'm trying to reverse the process and account for my header.

In other words I have my data frame in R:

BRANDNUMYEARVALUE
GMC1  1999  1
FORD   2  2000  12000
GMC1  2001   12500
 etc
and I make some edits.
BRANDNUMYEARVALUE
DODGE   3  1999  1
TOYOTA   4 2000  12000
DODGE3  2001   12500
So now I would need to ouput an XML file in the same format accounting
for my header (essentially, add z: in front of row).

(What I want to output)
   data
   z:row BRAND=DODGE NUM=3 YEAR=1999 VALUE=1 /
   z:row BRAND=TOYOTA NUM=4 YEAR=2000 VALUE=12000 /
   z:row BRAND=DODGE NUM=3 YEAR=2001 VALUE=12500 /
   z:row BRAND=TOYOTA NUM=4 YEAR=2002 VALUE=13000 /
   z:row BRAND=DODGE NUM=3 YEAR=2003 VALUE=14000 /
   z:row BRAND=TOYOTA NUM=4 YEAR=2004 VALUE=17000 /
   z:row BRAND=DODGE NUM=3 YEAR=2005 VALUE=15000 /
   z:row BRAND=DODGE NUM=3 YEAR=1967 VALUE=PRICELESS /
   z:row BRAND=TOYOTA NUM=4 YEAR=2007 VALUE=17500 /
   z:row BRAND=DODGE NUM=3 YEAR=2008 VALUE=22000 /
   /data
Thus far from the help I've found online I was trying to set up an
xmlTree xml - xmlTree()

and use xml$addTag to create nodes and put in the data from my data
frame.
I feel like I'm not really even close to a solution so I'm starting to
believe that this might not be the best path to go down.

Once again, any help is much appreciated.

AG


On Tue, Jan 22, 2013 at 6:04 PM, Duncan Temple Lang
dtemplel...@ucdavis.edu
 wrote:


 Hi Adam

  [You seem to have sent the same message twice to the mailing list.]

 There are various strategies/approaches to creating the data frame 
 from the XML.

 Perhaps the approach that most closely follows your approach is

   xmlRoot(doc)[ row ]

 which  returns a list of XML nodes whose node name is row that are 
 children of the root node data.

 So
   sapply(xmlRoot(doc) [ row ], xmlAttrs)

 yields a matrix with as many columns as there are  row nodes and 
 with 3 rows - one for each of the BRAND, YEAR and VALUE attributes.

 So

   d = t( sapply(xmlRoot(doc) [ row ], xmlAttrs) )

 gives you a matrix with the correct rows and column orientation and 
 now you can turn that into a data frame, converting the columns into 
 numbers, etc. as you want with regular R commands (i.e. independently 
 of the XML).


  D.

 On 1/22/13 1:43 PM, Adam Gabbert wrote:
   Hello,
 
  I'm attempting to read information from an XML into a data frame in 
  R
 using
  the XML package. I am unable to get the data into a data frame as 
  I
 would
  like.  I have some sample code below.
 
  *XML Code:*
 
  Header...
 
  Data I want in a data frame:
 
 data
row BRAND=GMC NUM=1 YEAR=1999 VALUE=1 /
row BRAND=FORD NUM=1 YEAR=2000 VALUE=12000 /
row BRAND=GMC NUM=1 YEAR=2001 VALUE=12500 /
row BRAND=FORD NUM=1 YEAR=2002 VALUE=13000 /
row BRAND=GMC NUM=1 YEAR=2003 VALUE=14000 /
row BRAND=FORD NUM=1 YEAR=2004 VALUE=17000 /
row BRAND=GMC NUM=1 YEAR=2005 VALUE=15000 /
row BRAND=GMC NUM=1 YEAR=1967 VALUE=PRICLESS /
row BRAND=FORD NUM=1 YEAR=2007 VALUE=17500 /
row BRAND=GMC NUM=1 YEAR=2008 VALUE=22000 /
/data
 
  *R Code:*
 
  doc -xmlInternalTreeParse (Sample2.xml) top - xmlRoot (doc) 
  xmlName (top) names (top) art - top [[row]] art
  **
  *Output:*
 
  artrow BRAND=GMC NUM=1 YEAR=1999 VALUE=1/
 
  * *
 
 
  This is where I am having difficulties.  I am unable to access
 additional
  rows; ( i.e.  row BRAND=GMC NUM=1 YEAR=1967 VALUE=PRICLESS 
  / )
 
  and I am unable to access the individual entries to actually create 
  the data frame.  The data frame I would like is as follows:
 
  BRANDNUMYEARVALUE
  

Re: [R] run R script automatically by double-clicking WinXP desktopicon

2009-09-23 Thread Franzini, Gabriele [Nervianoms]
Hello Chris,
I had the same problem, and I ended up driving R Gui through an Autoit
script, see http://www.autoitscript.com/autoit3/ Regards,
Gabriele Franzini


-Original Message-
From: cr...@binghamton.edu [mailto:cr...@binghamton.edu] 
Sent: 22 September 2009 19:37
To: r-help@r-project.org
Subject: Re: [R] run R script automatically by double-clicking WinXP
desktopicon

that helps, thanks. I can put a final line in my batch file that opens a
viewer for the png graph. 

I was hoping to find a way to do make it run in the Rgui (picky, I
know.) My graph is clearer in the default graph device that pops up in
the Rgui; it's blurry in the Windows viewer for png files. I should
probably play around with the resolution in R's png device. Or maybe
it's a function of the viewer I'm stuck using.

Thanks.

--Chris 

 Original message 
Date: Tue, 22 Sep 2009 11:41:50 -0400
From: Cedrick Johnson cedr...@cedrickjohnson.com
Subject: Re: [R] run R script automatically by double-clicking WinXP 
desktop icon
To: cr...@binghamton.edu
Cc: r-help@r-project.org

Here's something I use (in a batch file):

Rterm --no-restore --file=EveningStartup.r


Change EveningStartup.r to your particular file. When you create the 
shortcut, make sure to set the working directory to where your R script

is located. Then in your file, you could have the graphs write out to a

png file in a specified directory.

hth
c




cr...@binghamton.edu wrote:
 I've written a simple script that does some surveillance analysis on
daily counts of walk-in clinic visits, for our county health department.
(Actually, Michael Hohle's surveillance package does all the work; I
just customized it a little to work with the way our data are recorded.)
The output consists of a graph and a little table.

 My colleague will run it once in a while, on continuously updated
data. She knows nothing about R, at least not yet. I want to make it as
simple as possible. Rather than have her open R and type
source(filename), I want to be able to put an icon on her WinXP
desktop, so that when she double-clicks it, R will open, run the script,
and up pops the graph.

 I've been trying to learn about R CMD BATCH, playing with the
dialogue boxes for WinXP desktop shortcuts, etc, but no luck so far. I
guess I don't know enough about Windows.

 Can anyone tell me how to do this?  Thanks.

 --Chris Ryan

 __
 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 connectivity with Oracle DB

2009-05-29 Thread Franzini, Gabriele [Nervianoms]
Hello Madan, 
I am rather novice as well, so I went the ODBC way. 
If you define an ODBC connection to Oracle, with System DSN dsn-name,
the code to get the results of a query into, say, mydata is like :

library(RODBC) # First of all
channel - odbcConnect(dsn-name, uid=someuser) # double quotes
required, it will ask for the password
# Return rows from an SQL query
mydata - sqlQuery (channel, Select  put your query here ...) #
same as before
odbcClose(channel) # When you're done

HTH,
Gabriele Franzini 
ICT Applications Manager 
Nerviano Medical Sciences SRL 
Nerviano Italy 

__
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] Building GUI for custom R application

2009-04-15 Thread Franzini, Gabriele [Nervianoms]
Hello Harsh,
I found useful the fgui package ( 
http://www.people.fas.harvard.edu/~tjhoffm/fgui.html ). 
Regards,
Gabriele Franzini 
ICT Applications Manager 
Nerviano Medical Sciences SRL 
Nerviano Italy 




-Original Message-
From: Barry Rowlingson [mailto:b.rowling...@lancaster.ac.uk] 
Sent: 14 April 2009 12:55
To: Harsh
Cc: r-help@r-project.org
Subject: Re: [R] Building GUI for custom R application

On Tue, Apr 14, 2009 at 9:23 AM, Harsh singhal...@gmail.com wrote:
 HI R users,
 I would appreciate information/examples/suggestions on building GUIs 
 for R applications.
 I am currently working on a project that would require the following 
 functionalities :

 1) Display a  window to the user. Provide a function to scan local 
 drive and choose dataset file.
 2) Display the column names for the user to choose the dependent 
 variable and the independent variables.
 3) Fit regression and display statistics.

 Item 2 provides an example of creating a regression application with 
 slider controls for a parameter in loess function used in the example 
 application in that paper.
 For documentation on RGtk the author recommends reading the Gtk 
 tutorial and documentation. I seem to have difficulty in making sense 
 of the Gtk documentation since most of it is in C and documentation is 
 available for use of Gtk with Perl and Python. I am not a 
 C/Perl/Python programmer.
Barry

__
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] change default output size when using Sweave

2009-04-09 Thread Franzini, Gabriele [Nervianoms]
Hi,
I had a similar problem, and I took the direction of squeezing the
output into a minipage, e.g.:

...
@
\begin{minipage}[c]{0.6\textwidth}
fig=TRUE, echo=FALSE=
plot(...)
abline(...)
@
\end{minipage}
... 

HTH,
Gabriele Franzini 
ICT Applications Manager 
Nerviano Medical Sciences SRL 
Nerviano Italy 


-Original Message-
From: Mark Heckmann [mailto:mark.heckm...@gmx.de] 
Sent: 08 April 2009 10:31
To: 'Duncan Murdoch'
Cc: r-help@r-project.org
Subject: Re: [R] change default output size when using Sweave

Dear Duncan,

Thanks for the reply. This works, but unfortunately I need a different
solution.
My script is supposed to run completely automated and the graphics I
produce vary in size each time I run the script. But I want the graphics
to be fitted to my .pdf output without specifying the height argument
manually each time.
That is why I do not want a fixed height as a code chunk argument.
Actually I do not know if it is possible to have a variable placed in a
code chunk header. I tried the following which does not work:

=
size - 3
@

fig=TRUE, echo=TRUE, height=size=
   pushViewport(viewport(height = unit(80, mm)))
   grid.rect()
   grid.text(I want this viewport to be the whole output size)
   popViewport()
@

So still I face the problem to have Sweave generate a .pdf graphic that
is just as big I want it to be.
 
In the Sweave Docu paragraph A.9 I discovered something I use as a
workaround. I produce the .pdf output manually (where I can control the
size) and add each graphic to LaTex manually as well.
 
results=tex, echo=FALSE=
for (i in 1){
file=paste(myfile, i, .pdf, sep=)
pdf(file=file, paper=special, width=6, height=3)
   pushViewport(viewport(height = unit(5, inches))) 
   grid.rect()
   grid.text(I want this viewport to be the whole output size)
   popViewport()dev.off()
cat(\\includegraphics{, file, }\n\n, sep=) } @

I use parenthesis around the code as it prints out something I do not
want if no parenthesis are used (I use Windows). 

I am not too happy with the solution. I would prefer a more
straightforward approach to define the size of the output graphic. I
wonder if there are some Sweave settings that can be modified. 

In the Sweave manual (A.11) I found the following to customize the par
settings for each figure:

options(SweaveHooks=list(fig=function() par(bg=red, fg=blue)))

I wonder if something similar could be done changing the size of the
default output device (pdf or eps) for each figure like
pdf.options(height=2) or similar (it seems that this does not work)? 

I suppose this type of graphic customization is quite a common issue
when producing automated customized output/reports using R and Sweave
but I haven't found anything concerning this topic yet.

So I would be really glad if someone knows a solution.

TIA, Mark

__
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.