# [Rd] package building problem under Windows Vista

Gabor Grothendieck ggrothendieck at gmail.com
Sun Apr 20 14:43:50 CEST 2008

There does seem to be some general problem associated with Sweave
and graphics when I try it on my Vista system with
[1] "R version 2.7.0 RC (2008-04-17 r45367)"

appears to work properly; however, if we try it from the
command line:

to simulate what happens when trying to build the package it
indicates that in chunk 2 that pdf is masked from grDevices.
Then in chunk 17, when plotting is attempted the first time,
it chokes.

Maybe someone familiar with the relevant internals can explain.

I have shown chunks 1, 2 and 17 as output from Stangle,
the Rnw file up to the end of chunk 2 and the error log
from Sweave in the sections below.

-------------------------------------------------------------------------
###################################################
### chunk number 1:
###################################################
options(digits = 3, width = 60, scipen = 99)
set.seed(1)

cat.df.without.rownames <- function (d, file = ""){
stopifnot(is.data.frame(d))
row.names(d) <- 1:nrow(d)
x <- NULL
conn <- textConnection("x", "w", local = TRUE)
capture.output(print(d), file = conn)
close(conn)
cat(substring(x, first = max(nchar(row.names(d))) + 2), sep = "\n",
file = file)
}

###################################################
### chunk number 2:
###################################################

###################################################
### chunk number 17:
###################################################
plot(result.batched, "time.series.bps")

-------------------------------------------------------------------------

\documentclass[a4paper]{report}
\usepackage[round]{natbib}

\usepackage{Rnews}
\usepackage{fancyvrb}
\usepackage{Sweave}
\hyphenation{decision}

\DefineVerbatimEnvironment{Sinput}{Verbatim}{fontsize=\small,fontshape=sl}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{fontsize=\small}
\DefineVerbatimEnvironment{Scode}{Verbatim}{fontsize=\small,fontshape=sl}

%% \SweaveOpts{prefix.string=graphics/portfolio}

\bibliographystyle{abbrvnat}

\begin{document}
\begin{article}
\author{Jeff Enos, David Kane, Arjun Ravi Narayan, Aaron Schwartz,
Daniel Suo and Luyi Zhao}

<<echo = FALSE>>=
options(digits = 3, width = 60, scipen = 99)
set.seed(1)

cat.df.without.rownames <- function (d, file = ""){
stopifnot(is.data.frame(d))
row.names(d) <- 1:nrow(d)
x <- NULL
conn <- textConnection("x", "w", local = TRUE)
capture.output(print(d), file = conn)
close(conn)
cat(substring(x, first = max(nchar(row.names(d))) + 2), sep = "\n",
file = file)
}
@

\maketitle

\setkeys{Gin}{width=0.95\textwidth}

\section*{Introduction}

Trade costs are the costs a trader must pay to implement a decision to
buy or sell a security. Consider a single trade of a single equity
security. Suppose on the evening of August 1, a trader decides to
purchase 10,000 shares of IBM at \$10, the \emph{decision price} of the trade. The next day, the trader's broker buys 10,000 shares in a rising market and pays \$11 per share, the trade's \emph{execution price}.

How much did it cost to implement this trade?  In the most basic
ex-post analysis, trade costs are calculated by comparing the
execution price of a trade to a benchmark price.\footnote{For an
in-depth discussion of both ex-ante modeling and ex-post measurement
of trade costs, see \citet{kissell:glantz}.}  Suppose we
wished to compare the execution price to the price of the security at
the time of the decision in the above example.  Since the trader's
decision occurred at \$10 and the broker paid \$11, the cost of the
trade relative to the decision price was $\$11 - \$10 = \$1$per share, or \$10,000 (9.1\% of the total value of the execution).

Measuring costs relative to a trade's decision price captures costs
associated with the delay in the release of a trade into the market
and movements in price after the decision was made but before the
order is completed.  It does not, however, provide a means to
determine whether the broker's execution reflects a fair price. For
example, the price of \$11 would be a poor price if most transactions in IBM on August 2 occurred at \$10.50.  For this purpose a better
benchmark would be the day's volume-weighted average price, or VWAP.
If VWAP on August 2 was \$10.50 and the trader used this as her benchmark, then the trade cost would be \$0.50 per share, or \\$500.

The first version of the \pkg{tradeCosts} package provides a simple
framework for calculating the cost of trades relative to a benchmark
price, such as VWAP or decision price, over multiple periods and basic
reporting and plotting facilities to analyse these costs.

\section*{Trade costs in a single period}
Suppose we want to calculate trade costs for a single period.  First,
the data required to run the analysis must be assembled into three
data frames.  A sample of each of the three types of data has been included
with the package in three data sets.

The first data frame contains all trade-specific information, a sample
of which is in the \texttt{trade.mar.2007} data frame:

<<echo=TRUE>>=
@

-------------------------------------------------------------------------

Here is the result of sweaving:

Processing code chunks ...
1 : term verbatim
2 : echo term verbatim

The following object(s) are masked from package:grDevices :

pdf

3 : echo term verbatim
4 : echo term verbatim
5 : term verbatim
6 : echo term verbatim
7 : term verbatim
8 : echo term verbatim
9 : echo term verbatim
10 : term verbatim
11 : echo term verbatim
12 : term verbatim
13 : echo term verbatim
14 : term verbatim
15 : term verbatim
16 : term verbatim
17 : echo term verbatim eps pdf

Error:  chunk 17
Error in function (classes, fdef, mtable)  :
unable to find an inherited method for function "pdf", for signature "missing"

Execution halted

> Thanks for the suggestions.
>
> John
>
>
> >
> > I also have a problem with the vignettes (note
> > there are two) but as with you this works:
> >
> > Rcmd build --no-vignettes tradeCosts
> >
> > I don't have any special environment variables set for temporary
> > directories and I use C:\Program Files\R\...
> > for R.  I use Rcmd.bat and sweave.bat from batchfiles found at:
> > which finds R in the registry so no paths need be set.
> > I am on Vista but you seem to have SP1 which I don't
> > have yet.
> >
> > I can build other packages so there
> > is probably something that needs fixing in their vignettes.
> >
> > On Sat, Apr 19, 2008 at 7:52 AM, John Fox <jfox at mcmaster.ca> wrote:
> > > Dear list members,
> > >
> > > I've encountered the following problem trying to build a package
> > under
> > > Windows Vista (SP1). The problem occurs with both R 2.6.2 and R 2.7.0
> > RC
> > > (from which this output was produced). The package builds just fine
> > on my XP
> > >
> > > ---------- snip -------------
> > >
> > > Microsoft Windows [Version 6.0.6001]
> > >
> > > d:\R-packages>R CMD build tradeCosts
> > > * checking for file 'tradeCosts/DESCRIPTION' ... OK
> > > * preparing 'tradeCosts':
> > > * checking DESCRIPTION meta-information ... OK
> > > * installing the package to re-build vignettes
> > > installing R.css in
> > C:/Users/JOHNFO~1/AppData/Local/Temp/Rinst602447586
> > >
> > >
> > > ---------- Making package tradeCosts ------------
> > >  adding build stamp to DESCRIPTION
> > >  installing NAMESPACE file and metadata
> > > Error in file(file, "r") : unable to open connection
> > > Calls: <Anonymous> -> parseNamespaceFile -> parse -> file
> > > In addition: Warning message:
> > > In file(file, "r") :
> > >  cannot open file
> > > ts/NAMESPACE', reason 'Permission denied'
> > > Execution halted
> > > make[2]: *** [nmspace] Error 1
> > > make[1]: *** [all] Error 2
> > > make: *** [pkg-tradeCosts] Error 2
> > > *** Installation of tradeCosts failed ***
> > >
> > > Removing
> > > * creating vignettes ... OK
> > > * removing junk files
> > > * checking for LF line-endings in source and make files
> > > * checking for empty or unneeded directories
> > > * building 'tradeCosts_0.3-0.tar.gz'
> > >
> > >
> > > d:\R-packages>
> > >
> > > ---------- snip -------------
> > >
> > > I believe that the error is related to the vignette in the package,
> > since I
> > > can build packages without a vignette. Clearly there is a file-
> > permission
> > > problem but: (1) I'm using an account with administrator privileges;
> > (2) R
> > > is installed into c:\R (and the problem persists even when I install
> > R into
> > > d:\R); (3) the problem persists when I run the command window and R
> > itself
> > > as administrator, and when I turn off account controls; (4) the
> > problems
> > > persists when I reset the environment variables temp and tmp to
> > d:\temp and
> > > set the permissions to d:\temp so that all groups and users have full
> > > control over that directory.
> > >
> > > I'm tempted to dump Vista but I've been trying to persist with it
> > since most
> > > people (e.g., my students) buying new Windows machines will be
> > getting it.
> > > Although I've read section 2.24 of the R for Windows FAQ, it's quite
> > > possible that I've missed something of relevance there.
> > >
> > > Any help would be appreciated.
> > >
> > > Thanks in advance,
> > >  John
> > >
> > > --------------------------------
> > > John Fox, Professor
> > > Department of Sociology
> > > McMaster University
> > > Hamilton, Ontario, Canada L8S 4M4
> > > 905-525-9140x23604
> > > http://socserv.mcmaster.ca/jfox
> > >
> > > ______________________________________________
> > > R-devel at r-project.org mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-devel
> > >
>
>