[R] problems in sourcing R script

Ulrich Leopold uleopold at science.uva.nl
Mon Sep 18 11:35:26 CEST 2006


Dear list,

First my information:
platform       i386-pc-linux-gnu
arch           i386
os             linux-gnu
system         i386, linux-gnu
status
major          2
minor          3.1
year           2006
month          06
day            01
svn rev        38247
language       R
version.string Version 2.3.1 (2006-06-01)

Now my question:

How is it possible that a command in an R script is not executed completely
whereas the same command is fully executed when I copy paste it to the R
terminal?

It is the last command "summary(....)" which shows such behaviour.


The result of the execution is:


         Df Sum of Sq     RSS     AIC
<none>                 18.666 -49.277
- Flower  1     2.113  20.779 -45.700


It does not compute the summary statistics any more.

Whereas this is the result when I copy paste the comamnd into the R terminal:


         Df Sum of Sq     RSS     AIC
<none>                 18.666 -49.277
- Flower  1     2.113  20.779 -45.700

Call:
lm(formula = NH4Mar04 ~ Flower, data = N)

Residuals:
    Min      1Q  Median      3Q     Max
-1.0750 -0.1968 -0.1518 -0.0968  2.9632



Any ideas what the problem could be?

Is it possible that there is some kind of character problem or a hidden
control character in the text file or an encoding problem (I use UTF)? I
checked already with cat -A whether it shows unwanted control characters but
nothing showed up.
I also used 2 different text editors to see whetehr it is related to a text
editor.


Thanks, Ulrich


R.script sourced with
> source("script.R")

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

# Load MASS library for stepAIC, truehist, etc.
library(MASS)
# Read in the data as comma separated file
N <- read.csv2("MatrixNO3_08Aug06.csv", header=TRUE, sep=";", dec=".")

# Compute stepwise generalised linear regression
summary(stepAIC(lm(NH4Mar04~Elevation+Soil1+Soil2+Text1+Text2+Text3+Rice+Cabbage+Squash+Chilli+Flower,
N)))

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

And here is the example for reproduction:

N <-
structure(list(samplePCR... = as.integer(c(1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52)), Elevation = c(12.9,
12.9, 12.9, 12.9, 12.9, 12.9, 13.1, 13.1, 13.2, 13.3, 13.1, 13,
13.2, 13.3, 13.4, 13.6, 13.5, 13.5, 13.3, 13, 12.8, 13.8, 14.1,
13.2, 13.1, 12.5, 12, 11.8, 12.4, 13.8, 13.7, 12.8, 12.9, 12.8,
12.8, 12.7, 12.5, 12.4, 12.4, 12.5, 12.2, 12.3, 11.8, 13.7, 13.8,
13.8, 13.9, 13, 12.9, 13.9, 13.6, 13.8), Soil1 = as.integer(c(1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0)), Soil2 = as.integer(c(0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
1, 1, 1, 1, 1, 1)), Text1 = as.integer(c(1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 0, 0)), Text2 = as.integer(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1
)), Text3 = as.integer(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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
41.04, 37.18, 20.6, 18.12, 6.04, 22.85, 29.56, 28.35, 28.24,
20.35, 20.65, 22.85, 7.49, 10.8, 6.92, 31.8, 28.7, 24.2, 26.76,
18.16, 20.3, 35.16, 33.73, 21.73, 22.42, 27.88, 6.84, 10.52,
10.24, 20.04, 16.92), NO3Aug04 = c(13.84, 11.36, 4.64, 13.64,
12.64, 11.42, 19.87, 2.04, 11.76, 1.28, 13.06, 11.87, 2.68, 9.12,
2.68, 4.92, 14.85, 4.08, 10.75, 12.48, 16.68, 27.16, 22.28, 2.96,
12.88, 22.84, 15.35, 8.04, 8.66, 1.28, 23.84, 25.77, 28.6, 1.28,
23.18, 8.84, 20, 21.84, 9.98, 37.9, 17.8, 21.27, 10.32, 1.98,
0.83, 1.18, 2.68, 11.08, 14.44, 7.84, 13.88, 5.48), NH4Mar04 = c(0.76,
0.68, 0.79, 0.79, 0.79, 0.78, 0.77, 3.92, 1.12, 1.12, 0.66, 0.84,
0.84, 0.56, 1.12, 0.78, 0.56, 1.12, 0.65, 0.84, 0.67, 3.08, 0.93,
0.56, 0.77, 0.84, 0.81, 1.4, 0.86, 0.86, 0.79, 0.79, 0.81, 0.68,
0.84, 0.68, 1.4, 0.86, 0.82, 1.68, 0.77, 0.79, 0.84, 0.9, 0.8,
0.81, 0.84, 0.68, 0.56, 1.4, 3.08, 0.76), NH4Aug04 = c(0.78,
0.69, 2.24, 0.77, 1.12, 0.7, 0.98, 0.84, 0.71, 0.84, 0.75, 0.71,
1.12, 1.68, 0.84, 0.56, 0.81, 0.84, 0.67, 1.96, 0.87, 1.12, 1.4,
0.84, 0.75, 1.12, 0.83, 1.12, 0.6, 0.56, 1.11, 1.18, 1.96, 0.84,
1.09, 2.24, 1.4, 1.05, 0.65, 1.68, 0.84, 1.03, 1.12, 0.38, 0.34,
0.35, 1.4, 0.5, 1.68, 1.4, 1.96, 3.08), NO3Mar05 = c(5.5, 19.6,
6, 6.2, 5.6, 5.2, 5.1, 10.4, 12.2, 13.44, 9.7, 8.12, 5.88, 8.9,
7.8, 13.44, 12.6, 14.56, 14.4, 10.64, 11.5, 29.04, 22.08, 2.8,
5.5, 7, 6.1, 5.88, 12.6, 9.53, 4.9, 8.4, 5.9, 6.44, 12.32, 22.96,
7.28, 5.88, 6.12, 6.16, 1.96, 6.72, 6.46, 5.64, 5.38, 12.24,
5.04, 7.56, 2.96, 8.4, 1.68, 1.76), NO3Aug05 = c(6.74, 3.36,
2.8, 6.4, 8.2, 4.2, 8.2, 9.1, 9.46, 8.64, 8.57, 3.64, 5.87, 6.98,
7.48, 11.64, 4.48, 3.36, 7.86, 8.96, 7.68, 10.16, 12.8, 8.24,
5.25, 5.44, 6.24, 9.72, 8.67, 8.54, 12.4, 11.56, 11.04, 10.48,
9.64, 9.89, 8.08, 7.68, 6.84, 7.02, 6.89, 8.04, 5.76, 5.86, 6.26,
8.96, 13.07, 7.28, 11.28, 6.72, 7.46, 6.52), NH4Mar05 = c(0.84,
0.28, 0.84, 0.68, 0.84, 0.92, 0.96, 0.56, 0.62, 0.56, 0.48, 0.56,
0.84, 0.48, 0.62, 0.84, 0.95, 2.24, 0.58, 0.56, 0.52, 2.24, 0.28,
0.28, 0.72, 0.84, 0.72, 0.84, 0.96, 0.56, 0.68, 1.12, 0.7, 0.7,
0.56, 0.56, 0.56, 0.52, 0.54, 0.28, 0.84, 0.56, 0.56, 0.49, 0.5,
0.52, 0.56, 1.68, 0.22, 0.28, 0.28, 0.26), NH4Aug05 = c(0.64,
1.96, 0.56, 0.68, 0.64, 1.12, 0.76, 0.56, 0.6, 0.56, 0.62, 0.56,
0.64, 0.52, 0.62, 0.64, 0.56, 0.84, 0.78, 1.12, 0.68, 1.12, 1.24,
0.48, 0.58, 0.64, 0.63, 0.64, 0.76, 0.78, 1.68, 0.86, 0.74, 0.68,
0.56, 0.64, 0.62, 0.54, 0.52, 0.32, 0.64, 0.56, 0.58, 0.58, 0.48,
0.54, 0.72, 2.24, 0.84, 0.56, 0.38, 0.36)), .Names = c("samplePCR...",
"Elevation", "Soil1", "Soil2", "Text1", "Text2", "Text3", "Rice",
"Cabbage", "Squash", "Chilli", "Flower", "NO3Mar04", "NO3Aug04",
"NH4Mar04", "NH4Aug04", "NO3Mar05", "NO3Aug05", "NH4Mar05", "NH4Aug05"
), class = "data.frame", row.names = c("1", "2", "3", "4", "5",
"6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16",
"17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27",
"28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38",
"39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
"50", "51", "52"))



_______________________________________________

Ulrich Leopold MSc.

Dep. Phys. Geography and Soil Science
Inst. for Biodiversity and Ecosystem Dynamics
Faculty of Science
University of Amsterdam
Nieuwe Achtergracht 166
NL-1018 WV Amsterdam

Phone: +31-(0)20-525-7456 (7451 Sectretary)
Fax:   +31-(0)20-525-7431
Email: uleopold at science.uva.nl
http://www.science.uva.nl/ibed/cbpg/index.html



More information about the R-help mailing list