Re: [R] Variable and value labels

2023-07-13 Thread Adrian Dușa
Anupam,

This is very general, and it also depends on the scientific domain.
Factors do solve the value labels, but they drop the (original) values.
They also lose the connection to the different types of missing values (an
important topic in the social sciences).

Base R provides as much as it can, but it cannot possibly cover all
applications out there, so an add-on package is a must.
A good way to do both variable and value labels, as well as different types
of missing values, is the package "declared".

I hope this helps,
Adrian

On Wed, Jul 12, 2023 at 6:55 AM Anupam Tyagi  wrote:

> Hello,
>
> is there an easy way to do variable and value labels (for factor variables)
> in base-R, without using a package. If not, what is an easy and good way to
> do labels, using an add-on package.
>
> --
> Anupam.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>


-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr. 90-92
050663 Bucharest sector 5
Romania
https://adriandusa.eu

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] replacing unicode characters

2023-06-30 Thread Adrian Dușa
Hello Iris,

Thanks for your answer. The thing is not that I want to obtain ,
but that it gets produced regardless.
In the meantime, I have assessed the real culprit is somehow (perhaps)
related to the locale or encoding of the terminal process that I use to run
R, in that particular MacOS Electron application (it doesn't happen on
Windows).

In a very simple test, I tried creating a text file from the Electron app
embedded R:
sink("test.txt")
cat("\u00e7")
sink()

which resulted in:



I don't quite understand how this works, my best guess is it matters less
how R interprets these characters, but how they are passed through the
child process that started R.
I'd be grateful for any hint in this direction, if anyone has experience.

Best wishes,
Adrian

On Thu, Jun 29, 2023 at 1:59 AM Iris Simmons  wrote:

> Hiya!
>
>
> You can do this by specifying sub="c99" instead of "Unicode":
>
> ```R
> x <- "fa\xE7ile"
> xx <- iconv(x, "latin1", "UTF-8")
> iconv(xx, "UTF-8", "ASCII", "c99")
> ```
>
> produces:
>
> ```
> > x <- "fa\xE7ile"
> > xx <- iconv(x, "latin1", "UTF-8")
> > iconv(xx, "UTF-8", "ASCII", "c99")
> [1] "fa\\u00e7ile"
> >
> ```
>
> For future reference, you can find this in section Examples of the
> help page ?iconv
> I hope this helps!
>
> On Wed, Jun 28, 2023 at 3:09 PM Adrian Dușa  wrote:
> >
> > Dear list,
> >
> > Building on the example from ?iconv:
> > x <- "fa\xE7ile"
> > xx <- iconv(x, "latin1", "UTF-8") # "façile"
> >
> > and:
> >
> > iconv(xx, "UTF-8", "ASCII", "Unicode")
> > # "faile"
> >
> > This is the type of result I sometimes get from an R script that I cannot
> > reproduce here, because it depends on a terminal process started in a
> > compiled Electron (Node.js) application, under MacOS.
> >
> > I was wondering, is there a standard way, perhaps also using iconv(), to
> > convert this type of result to a more manageable unicode representation?
> >
> > Something like: "fa\u00e7ile"
> >
> > Or perhaps a clever regexp, for any number of such occurrences in a
> string?
> >
> > Thanks a lot in advance,
> > Adrian
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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.
>


-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr. 90-92
050663 Bucharest sector 5
Romania
https://adriandusa.eu

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] replacing unicode characters

2023-06-28 Thread Adrian Dușa
Dear list,

Building on the example from ?iconv:
x <- "fa\xE7ile"
xx <- iconv(x, "latin1", "UTF-8") # "façile"

and:

iconv(xx, "UTF-8", "ASCII", "Unicode")
# "faile"

This is the type of result I sometimes get from an R script that I cannot
reproduce here, because it depends on a terminal process started in a
compiled Electron (Node.js) application, under MacOS.

I was wondering, is there a standard way, perhaps also using iconv(), to
convert this type of result to a more manageable unicode representation?

Something like: "fa\u00e7ile"

Or perhaps a clever regexp, for any number of such occurrences in a string?

Thanks a lot in advance,
Adrian

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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-pkgs] new version of package declared

2022-09-29 Thread Adrian Dușa
Dear R-list,

It gives me great pleasure to announce the release of version 0.18 of
package declared, that makes a difference between empty missing values (the
current NAs in R) and declared missing values (NAs with a reason).

Besides an automatic detection of such values by most base R operations
(including ==, != etc.), package declared also offers weighted versions of
most common summaries (ex. mean, median, sd, quantile) that also apply on
the declared missing values, something not covered by other similar
functions.

Version 0.18 is fully documented using Roxygen2 and extensively (even
obsessively) tested to achieve no less than 100% code coverage, using more
than 750 tests including the "golden" ones capturing output using
snapshots. It also features three Vignettes showcasing the package's
features.

Many thanks to Daniel Antal for the enthusiastic support and contribution
to the initial Roxygen2 and pkgdown documentation, bringing this package
closer to the rOpenSci standards. Most functions are now generic, allowing
extensions to any type of object, for both creation and coercion to class
"declared".

Platform specific binaries are soon to be built on CRAN, but they are also
available and can be installed from R-universe package page:
https://dusadrian.r-universe.dev/ui#package:declared

As always, bug reporting and feature proposals are more than welcome.
Adrian

[[alternative HTML version deleted]]

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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-pkgs] new version of package declared

2022-03-17 Thread Adrian Dușa
Dear community,

Version 0.12 of the package declared has just made it on CRAN.

Apart from the usual functions to declare labels for regular and missing
values, this version has a suite of new functions to calculate various
weighted frequencies and summaries.

The weighted versions are heavily inspired from the base R packages and
other established contributed ones, but adapted to objects of class
"declared".

In hoping this might be helpful,

Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr. 90-92
050663 Bucharest sector 5
Romania
https://adriandusa.eu

[[alternative HTML version deleted]]

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Creating NA equivalent

2021-12-26 Thread Adrian Dușa
Responding a bit slow during holidays.
Indeed, following Ducan Murdoch's advice I created the package declared
which has a simple mechanism of attributing different interpretations for
the same NA value, within a vector.

I learned there is no need for different NA values, the built in NA is
enough. By allocating different interpretations (labels), the end result is
similar as if we had different NA values, all in base R.

This meta-information can subsequently be used for any conceivable purpose,
including what I read in this thread about censoring etc.

I hope this helps, best wishes and season's greetings,
Adrian

On Tue, 21 Dec 2021 at 21:45, Avi Gross  wrote:

> I wonder if the package Adrian Dușa created might be helpful or point you
> along the way.
>
> It was eventually named "declared"
>
> https://cran.r-project.org/web/packages/declared/index.html
>
> With a vignette here:
>
> https://cran.r-project.org/web/packages/declared/vignettes/declared.pdf
>
> I do not know if it would easily satisfy your needs but it may be a step
> along the way. A package called Haven was part of the motivation and Adrian
> wanted a way to import data from external sources that had more than one
> category of NA that sounds a bit like what you want. His functions should
> allow the creation of such data within R, as well. I am including him in
> this email if you want to contact him or he has something to say.
>
>
> -Original Message-
> From: R-help  On Behalf Of Duncan Murdoch
> Sent: Tuesday, December 21, 2021 5:26 AM
> To: Marc Girondot ; r-help@r-project.org
> Subject: Re: [R] Creating NA equivalent
>
> On 20/12/2021 11:41 p.m., Marc Girondot via R-help wrote:
> > Dear members,
> >
> > I work about dosage and some values are bellow the detection limit. I
> > would like create new "numbers" like LDL (to represent lower than
> > detection limit) and UDL (upper the detection limit) that behave like
> > NA, with the possibility to test them using for example is.LDL() or
> > is.UDL().
> >
> > Note that NA is not the same than LDL or UDL: NA represent missing data.
> > Here the data is available as LDL or UDL.
> >
> > NA is built in R language very deep... any option to create new
> > version of NA-equivalent ?
> >
>
> There was a discussion of this back in May.  Here's a link to one approach
> that I suggested:
>
>https://stat.ethz.ch/pipermail/r-devel/2021-May/080776.html
>
> Read the followup messages, I made at least one suggested improvement.
> I don't know if anyone has packaged this, but there's a later version of
> the code here:
>
>https://stackoverflow.com/a/69179441/2554330
>
> Duncan Murdoch
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] .Rdata not loading

2021-12-24 Thread Adrian Dușa
On Fri, 24 Dec 2021 at 17:35, Rich Shepard  wrote:

> On Fri, 24 Dec 2021, Rasmus Liland wrote:
>
> > If you want to look at Rdata-files in a quick way in the
> > terminal, use this little gem in your .zshrc.local:
> >
> > readrdata() { Rscript -e "options(width=$COLUMNS); load('$1');
> sapply(ls(), get, simplify=F)" | less }
>
> Rasmus,
>
> I use bash, not zsh. And running the readdata() command in R produces no
> output.
>

Package admisc has a function called obj.rda(), which returns the names of
the objects from an .Rdata file.
Not sure how it handles corrupt .Rdata files, but should generally give an
idea about what's inside.

Hth,
Adrian

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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-pkgs] CRAN has a new package: declared

2021-06-18 Thread Adrian Dușa
Dear All,

A new package called 'declared' has made it to CRAN (platform specific
binaries in due course). This might be useful for social scientists, where
multiple (types of) missing values are declared for any given variable.

The package has a similar functionality to packages 'haven' and 'labelled',
with one but important difference: instead of treating existing values as
NAs, package declared interprets NAs as existing values (details in the
embedded vignette). Users do not have to do anything else in the subsequent
analyses, since the declared values are stored as regular NAs.

My most sincere thanks to all contributors from the r-devel list who
expressed their points regarding the treatment of missing values in R, and
especially to Duncan Murdoch who provided the starting solution.

Special thanks to Avi Gross for the subsequent email exchanges, revision of
the package and its vignette.

Hope this will prove useful, I would be grateful for feedback and bug
reports.

--
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr. 90-92
050663 Bucharest sector 5
Romania
https://adriandusa.eu

[[alternative HTML version deleted]]

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] problems in converting numeric to character

2018-06-07 Thread Adrian Dușa
Does this helps?

> formatC(x, digits = 1, format = "f")
[1] "1.0" "2.0" "2.0" "2.1"


On Thu, Jun 7, 2018 at 10:08 PM 刘瑞阳  wrote:

> Hi,
> I am having trouble converting numeric to characters in the format I
> desire. To be more specific, I have a number of numeric as follows:
>
> x<-c(1.0,2.0,2.00,2.1)
> I want to convert them to characters so that the out put would be
> c(“1.0”,”2.0”,”2.00”,”2.1”).
>
> However, I used as.character(x) and the output is:
> "1"   "2"   "2"   “2.1"
>
> The decimals are removed if the numeric ends with “.0”. Is there a way to
> circumvent this problem?
>
> Thanks very much!
>
> Sincerely,
>
> Ruiyang Liu
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Help

2017-06-20 Thread Adrian Dușa
One solution, among many, involving recoding. There is a function in
package QCA called recode()
(similar, but in my opinion more flexible than the same function recode()
in package car)

> library(QCA)
> ind.davis$Ageclass <- recode(ind.davis$Ageclass, "adult = Adult; Juvanile
 = Juvenile; sub-adult = Sub-adult", as.factor.result = TRUE)

Should work, although untested (your example is not replicable).

Hope this helps,
Adrian

On Tue, Jun 20, 2017 at 8:06 AM, Leonardo Malaguti <
leonardomalagut...@gmail.com> wrote:

> Dear expert friends,
> I'm pretty young of this world and  my question at your eyes can be petty
> easy.
> I'll need to change the name of the levels inside a column of my data-frame
>
> levels(ind.davis$Ageclass) <- c("adult", "Juvanile", "sub-adult")
> names(ind.davis$Ageclass) <- c("Adult", "Juvenile", "Sub-adult")
> that is what I tried but of course doesn't work.
>
> Thanks,
> have a wonderful day,
> Leo
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>



-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr. 90-92
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] A strange arithmetic error in R (maybe a bug)

2017-02-18 Thread Adrian Dușa
There is no bug, of course, this is a common floating point arithmetic
misunderstanding.

> print(2.01, digits = 20)
[1] 2.0097868

Please search for "What every scientist should know about floating-point
arithmetic" and you'll hopefully understand what the "bug" is.

Hth,
Adrian



On Sat, Feb 18, 2017 at 6:18 AM, T. Zhang  wrote:

> Hello,
>
> Today I happened to notice a strange error in R. If you type
> (2.01-0.06)==1.95, output from R is “FALSE”, which is wrong. But if you
> type (1.01-0.06)==0.95, output is “TRUE”, which is correct. I tested this
> in two systems: R 3.3.2 in my iMac and R 3.2.0 on my school’s Linux server.
> Both gave same outputs. As shown in the following:
>
> > 2.01-0.06
> [1] 1.95
> > (2.01-0.06)==1.95  # should be TRUE; output is wrong
> [1] FALSE
> > 1.01-0.06
> [1] 0.95
> > (1.01-0.06)==0.95  # should be TRUE; output is correct
> [1] TRUE
> > (2.01-0.06)>1.95  # should be FALSE; output is correct
> [1] FALSE
> > (2.01-0.06)<1.95  # should be FALSE; output is wrong
> [1] TRUE
>
> Similar errors could be found with simple alterations of the above inputs,
> such as:
> > 5.533-5.412
> [1] 0.121
> > (5.533-5.412)==0.121  # should be TRUE; output is wrong
> [1] FALSE
> > 2.533-2.412
> [1] 0.121
> > (2.533-2.412)==0.121  # should be TRUE; output is correct
> [1] TRUE
>
> Could any of you test whether you have same outputs as mine? And does
> anyone know what is wrong with these? My guess is that R has a bug in
> processing double numbers. Thanks!
>
> TZ
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.




-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr. 90-92
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Beginner needs help with R

2017-02-06 Thread Adrian Dușa
Two methods, among others:

seq1 <- paste("DQ", sprintf("%0*d", 6, seq(060054, 060060)), sep = "")

or

seq1 <- paste("DQ", formatC(seq(060054, 060060), dig = 5, flag = 0), sep =
"")

Hth,
Adrian


On Mon, Feb 6, 2017 at 3:50 AM, Nabila Arbi 
wrote:

> Dear R-Help Team!
>
> I have some trouble with R. It's probably nothing big, but I can't find a
> solution.
> My problem is the following:
> I am trying to download some sequences from ncbi using the ape package.
>
> seq1 <- paste("DQ", seq(060054, 060060), sep = "")
>
> sequences <- read.GenBank(seq1,
> seq.names = seq1,
> species.names = TRUE,
> gene.names = FALSE,
> as.character = TRUE)
>
> write.dna(sequences, "mysequences.fas", format = "fasta")
>
> My problem is, that R doesn't take the whole sequence number as "060054"
> but it puts it as DQ60054 (missing the zero in the beginning, which is
> essential).
>
> Could please tell me, how I can get R to accepting the zero in the
> beginning of the accession number?
>
> Thank you very much in advance and all the best!
>
> Nabila
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>



-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr. 90-92
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Loop to check for large dataset

2016-10-10 Thread Adrian Dușa
Granted,, there are better solutions than my "KISS" (keep it simple and
stupid) example.

Hopefully, Christoph will have learned from both.

Best,
Adrian

On 10 Oct 2016 13:44, "PIKAL Petr"  wrote:

> Hi
>
>
>
> Given this example data, you can get same answer with less typing and
> without loops.
>
>
>
> res<-xtabs(~W+P+S,mydata)
>
> res1<-which(res==0, arr.ind=T)
>
> head(res1)
>
>   W P S
>
> 10   10 1 1
>
> 11   11 1 1
>
> 82   82 1 1
>
> 100 100 1 1
>
> 117 117 1 1
>
> 148 148 1 1
>
>
>
> Cheers
>
> Petr
>
>
>
>
>
> *From:* dusa.adr...@gmail.com [mailto:dusa.adr...@gmail.com] *On Behalf
> Of *Adrian Du?a
> *Sent:* Monday, October 10, 2016 12:26 PM
> *To:* Christoph Puschmann 
> *Cc:* r-help@r-project.org; PIKAL Petr 
> *Subject:* Re: [R] Loop to check for large dataset
>
>
>
> This is an example of how a reproducible code looks like, assuming you
> have three columns in your dataset named S (store), P (product) and W
> (week), and also assuming they have integer values from 1 to 19, 1 to 22
> and 1 to 157 respectively:
>
> #
>
> mydata <- expand.grid(seq(19), seq(22), seq(157))
> names(mydata) <- c("S", "P", "W")
>
> # randomly delete 65626 - 63127 = 2499 rows
> set.seed(12345) # make it replicable
>
> mydata <- mydata[-sample(seq(nrow(mydata)), nrow(mydata) - 63127), ]
>
> #
>
>
> Now the dataframe mydata contains exactly 63127 rows, just as in your
> case. The task is to find which weeks are missing, from which store and for
> which product.
>
> Below is a possible code to do that. Given you have a small number of
> stores and products, I'll keep it simple and stupid, by using for loops:
>
>
>
>
>
> #
>
>
>
> result <- matrix(nrow = 0, ncol = 3)
>
>
>
> for (i in seq(19)) {
>
> for (j in seq(22)) {
>
> miss <- setdiff(seq(157), mydata$W[mydata$S == i & mydata$P == j])
>
> if (length(miss) > 0) {
>
> result <- rbind(result, cbind(S = i, P = j, W = miss))
>
> }
>
> }
>
> }
>
>
>
> # The result matrix contains 2499 rows that are missing.
>
>
>
> > head(result)
>
>  S P   W
>
> [1,] 1 1  10
>
> [2,] 1 1  11
>
> [3,] 1 1  82
>
> [4,] 1 1 100
>
> [5,] 1 1 117
>
> [6,] 1 1 148
>
>
>
> #
>
>
>
>
>
> In this example, for S(tore) number 1 and P(roduct) number 1, you are
> missing W(eek) 10, 11, 82 and so on.
>
>
>
> In hoping you can adapt this code to your particular example,
>
> Adrian
>
>
>
> On Sun, Oct 9, 2016 at 2:26 AM, Christoph Puschmann <
> c.puschm...@student.unsw.edu.au> wrote:
> >
> > Dear Adrian,
> >
> > Yes it is a cyclical data set and theoretically it should repeat this
> interval until 61327. The data set itself is divided into 2 Parts:
> > 1. Product category (column 10)
> > 2. Number of Stores Participating (column 01)
> > Overall there are 22 different products and in each you have 19
> different stores participating. And theoretically each store over each
> product category should have a 1 - 157 week interval.
> >
> > The part I am struggling with is how do I run a loop over the whole data
> set, while checking if all stores participated 157 weeks over the different
> products.
> >
> > So far I came up with this:
> >
> > n=61327   # Generate Matrix to check for values
> > Control = matrix(
> >   0,
> >   nrow = n,
> >   ncol = 1)
> >
> > s <- seq(from =1 , to = 157, by = 1)
> > CW = matrix(
> >   s,
> >   nrow = 157,
> >   ncol = 1
> > )
> >
> > colnames(CW)[1] <- ’s'
> >
> > CW = as.data.frame(CW)
> >
> > for (i in 1:nrow(FD)) {   # Let run trhough all the rows
> >   for (j in 1:157) {
> > if(FD$WEEk[j] == C$s[j]) {
> >   Control[i] = 1 # coresponding control row = 1
> > } else {
> >   Control[i] = 0 # corresponding control row = 0
> > }
> > }
> > }
> >
> > I coded a  MRE and attached an sample of my data set.
> >
> > MRE:
> >
> > #MRE
> >
> > dat <- data.frame(
> >   Store = c(rep(8, times = 157), rep(12, times = 157)),  # Number of
> stores
> >   WEEK = rep(seq(from=1, to = 157, by = 1), times = 2)
> > )
> >
> >
> >
> >
>
>
>
> --
> Adrian Dusa
> University of Bucharest
> Romanian Social Data Archive
> Soseaua Panduri nr.90
> 050663 Bucharest sector 5
> Romania
>
> --
> Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou
> určeny pouze jeho adresátům.
> Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě
> neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie
> vymažte ze svého systému.
> Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email
> jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
> Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi
> či zpožděním přenosu e-mailu.
>
> V případě, že je tento e-mail součástí obchodního jednání:
> - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření
> smlouvy, a to z 

Re: [R] Loop to check for large dataset

2016-10-10 Thread Adrian Dușa
This is an example of how a reproducible code looks like, assuming you have
three columns in your dataset named S (store), P (product) and W (week),
and also assuming they have integer values from 1 to 19, 1 to 22 and 1 to
157 respectively:

#

mydata <- expand.grid(seq(19), seq(22), seq(157))
names(mydata) <- c("S", "P", "W")

# randomly delete 65626 - 63127 = 2499 rows
set.seed(12345) # make it replicable

mydata <- mydata[-sample(seq(nrow(mydata)), nrow(mydata) - 63127), ]

#


Now the dataframe mydata contains exactly 63127 rows, just as in your case.
The task is to find which weeks are missing, from which store and for which
product.
Below is a possible code to do that. Given you have a small number of
stores and products, I'll keep it simple and stupid, by using for loops:


#

result <- matrix(nrow = 0, ncol = 3)

for (i in seq(19)) {
for (j in seq(22)) {
miss <- setdiff(seq(157), mydata$W[mydata$S == i & mydata$P == j])
if (length(miss) > 0) {
result <- rbind(result, cbind(S = i, P = j, W = miss))
}
}
}

# The result matrix contains 2499 rows that are missing.

> head(result)
 S P   W
[1,] 1 1  10
[2,] 1 1  11
[3,] 1 1  82
[4,] 1 1 100
[5,] 1 1 117
[6,] 1 1 148

#


In this example, for S(tore) number 1 and P(roduct) number 1, you are
missing W(eek) 10, 11, 82 and so on.

In hoping you can adapt this code to your particular example,
Adrian


On Sun, Oct 9, 2016 at 2:26 AM, Christoph Puschmann <
c.puschm...@student.unsw.edu.au> wrote:
>
> Dear Adrian,
>
> Yes it is a cyclical data set and theoretically it should repeat this
interval until 61327. The data set itself is divided into 2 Parts:
> 1. Product category (column 10)
> 2. Number of Stores Participating (column 01)
> Overall there are 22 different products and in each you have 19 different
stores participating. And theoretically each store over each product
category should have a 1 - 157 week interval.
>
> The part I am struggling with is how do I run a loop over the whole data
set, while checking if all stores participated 157 weeks over the different
products.
>
> So far I came up with this:
>
> n=61327   # Generate Matrix to check for values
> Control = matrix(
>   0,
>   nrow = n,
>   ncol = 1)
>
> s <- seq(from =1 , to = 157, by = 1)
> CW = matrix(
>   s,
>   nrow = 157,
>   ncol = 1
> )
>
> colnames(CW)[1] <- ’s'
>
> CW = as.data.frame(CW)
>
> for (i in 1:nrow(FD)) {   # Let run trhough all the rows
>   for (j in 1:157) {
> if(FD$WEEk[j] == C$s[j]) {
>   Control[i] = 1 # coresponding control row = 1
> } else {
>   Control[i] = 0 # corresponding control row = 0
> }
> }
> }
>
> I coded a  MRE and attached an sample of my data set.
>
> MRE:
>
> #MRE
>
> dat <- data.frame(
>   Store = c(rep(8, times = 157), rep(12, times = 157)),  # Number of
stores
>   WEEK = rep(seq(from=1, to = 157, by = 1), times = 2)
> )
>
>
>
>



--
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Loop to check for large dataset

2016-10-08 Thread Adrian Dușa
It would help to have a minimal, reproducible example.
Unless revealing the structure of your FD object, it is difficult to
understand how a column having 61327 values would be "consistent over an 1
to 157 interval": is this interval cyclic until it reaches 61327 values?

>From your example using FD$WEEK, you are using a column called WEEK within
a dataframe names FD, and you only loop over the first 157 values of that
column. So where is the "column having 61327 values"?

For these types of problems you don't even need a loop, R is a vectorised
language (please note that you have a double loop but never use the "i"
one).

Very unclear, so please try to create a MRE, as the posting guide advices.


On Fri, Oct 7, 2016 at 11:22 PM, Christoph Puschmann <
c.puschm...@student.unsw.edu.au> wrote:

> Hey all,
>
> I would like to know if anyone, can put in the right direction of the
> following problem:
>
> I am currently want to use it to check if a column with a length of 61327
> is consistent over an 1 to 157 interval until the end of the column. In the
> case the interval is interrupted I want to know which values are missing
> and where the missing values are located. I started of with the following
> code to assign 1s, if we have a number ≤ 157 and 0 if not.
>
>
>
> I tried to do a double loop:
>
>
>
> n=61327
> Control = matrix(
> 0,
> nrow = n,
> ncol = 1)
>
>
>
> for (i in length(FD$WEEK)) {
> for (j in 1:157) {
> if(FD$WEEK[j] <=  157) {
>   Control[,1] = 1
> } else {
>   Control[,1] = 0
>   }
> }
> }
>
>
>
> I believe that this code is not correct, but I am unable to wrap my head
> around how I can check that the interval always will be followed.
>
> All the best,
>
> Christoph
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.




-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] separate commands by semicolon

2016-09-19 Thread Adrian Dușa
Oh yes, completely forgot about partial parsing. One possible (quick)
solution:

txt <- "print(2); bar <- \"don't ; use semicolons\"; foo <- '3;4'; ls("
sf <- srcfile("txt")
tryit <- tryCatch(parse(text = txt, srcfile = sf), error = identity)
gpd <- getParseData(sf)
pos <- c(0, gpd$col1[gpd$token == "';'"], nchar(txt) + 1)
final <- c()
for (i in seq(length(pos) - 1)) {
final <- c(final, substr(txt, pos[i] + 1, pos[i + 1] - 1))
}

Which outputs:
[1] "print(2)"   " bar <- \"don't ; use
semicolons\""
[3] " foo <- '3;4'"  " ls("

Excellent, thanks very much,
Adrian



On Mon, Sep 19, 2016 at 3:19 PM, Duncan Murdoch <murdoch.dun...@gmail.com>
wrote:

> On 19/09/2016 7:59 AM, Adrian Dușa wrote:
>
>> On Sun, Sep 18, 2016 at 12:34 AM, Peter Langfelder <
>> peter.langfel...@gmail.com> wrote:
>>
>> > On Sat, Sep 17, 2016 at 2:12 PM, David Winsemius <
>> dwinsem...@comcast.net>
>> > wrote:
>> > > Not entirely clear. If you were intending to just get character output
>> > then you could just use:
>> > >
>> > > strsplit(txt, ";")
>> >
>> > You would want to avoid splitting within character strings
>> > (print(";")) and in comments (print(2); ls() # This prints 2; then
>> > lists...) The comment char could also appear in a character string,
>> > where it does not mean the start of a comment...
>>
>>
>> Yes, that would be the problem.
>> Returning to my original post, modifying the example:
>>
>> x <- "print(2); bar <- \"don't ; use semicolons\"; foo <- '3;4'; ls("
>>
>> This should result in a character vector of length 4:
>> [1] "print(2)"  "bar <- \"don't ; use
>> semicolons\""
>> [3] "foo <- '3;4'"  "ls("
>>
>> even though the last command would cause an error using parse(text = x)
>>
>> Perhaps this is not that important (I am trying to simulate a normal R
>> console), and parse only if it syntactically correct.
>> I was merely curious if this could be done, likely using regular
>> expressions (surely strsplit doesn't solve it).
>>
>> Best,
>> Adrian
>>
>> See the section on "partial parsing" in the ?parse help page.
>
> Duncan Murdoch
>
>


-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] separate commands by semicolon

2016-09-19 Thread Adrian Dușa
On Sun, Sep 18, 2016 at 12:34 AM, Peter Langfelder <
peter.langfel...@gmail.com> wrote:

> On Sat, Sep 17, 2016 at 2:12 PM, David Winsemius 
> wrote:
> > Not entirely clear. If you were intending to just get character output
> then you could just use:
> >
> > strsplit(txt, ";")
>
> You would want to avoid splitting within character strings
> (print(";")) and in comments (print(2); ls() # This prints 2; then
> lists...) The comment char could also appear in a character string,
> where it does not mean the start of a comment...


Yes, that would be the problem.
Returning to my original post, modifying the example:

x <- "print(2); bar <- \"don't ; use semicolons\"; foo <- '3;4'; ls("

This should result in a character vector of length 4:
[1] "print(2)"  "bar <- \"don't ; use semicolons\""
[3] "foo <- '3;4'"  "ls("

even though the last command would cause an error using parse(text = x)

Perhaps this is not that important (I am trying to simulate a normal R
console), and parse only if it syntactically correct.
I was merely curious if this could be done, likely using regular
expressions (surely strsplit doesn't solve it).

Best,
Adrian

-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] separate commands by semicolon

2016-09-17 Thread Adrian Dușa
There is one minor problem with parse(): if any of the individual commands
has an error, the entire text will be parsed in a single error.

For example, in a normal R console:

> print(2); ls(
[1] 2
+

So first print(2) is executed, and only after the console expects the user
to continue the command from ls(
Parsing the same text:

> parse(text = "print(2); ls(")
Error in parse(text = "print(2); ls(") :
  :2:0: unexpected end of input
1: print(2); ls(
   ^

What I would need is something to separate the two commands, irrespective
of their syntactical correctness:

[1] "print(2)" "ls("

I hope this explains the situation,
Adrian

On Thu, Sep 15, 2016 at 11:02 PM, Adrian Dușa <dusa.adr...@unibuc.ro> wrote:

> On Thu, Sep 15, 2016 at 10:28 PM, William Dunlap <wdun...@tibco.com>
> wrote:
>
>> The most reliable way to split such lines is with parse(text=x).
>> Regular expressions don't do well with context-free grammars.
>>
>
> Oh, that's right of course.
> > as.character(parse(text = x))
> [1] "foo <- \"3;4\"""bar <- \"don't ; use semicolons\""
>
> That was simple enough, thanks very much,
> Adrian
>
> --
> Adrian Dusa
> University of Bucharest
> Romanian Social Data Archive
> Soseaua Panduri nr.90
> 050663 Bucharest sector 5
> Romania
>



-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] separate commands by semicolon

2016-09-15 Thread Adrian Dușa
On Thu, Sep 15, 2016 at 10:28 PM, William Dunlap  wrote:

> The most reliable way to split such lines is with parse(text=x).
> Regular expressions don't do well with context-free grammars.
>

Oh, that's right of course.
> as.character(parse(text = x))
[1] "foo <- \"3;4\"""bar <- \"don't ; use semicolons\""

That was simple enough, thanks very much,
Adrian

-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] separate commands by semicolon

2016-09-15 Thread Adrian Dușa
Dear R-helpers,

When parsing a text, I would like to separate commands written on the same
line, by a semicolon.
Something like:

x <- "foo <- '3;4'; bar <- \"don't ; use semicolons\""

Ideally, that would translate to these two commands in a character vector
of length 2:
foo <- '3;4'
bar <- "don't ; use semicolons"

It's probably a regexp magic, but I just can't find it.

Any hint is highly appreciated,
Adrian

-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] evaluating expressions as R console

2016-09-05 Thread Adrian Dușa
I think I have found a working solution. Rather ugly, but working and will
keep looking for better alternatives, though.

The procedure involves:

- parsing one line at a time
- if incomplete, parse as many lines as necessary to form an expression
- determine all expressions in the original input
- evaluate each expression, one at a time
  (which shows individual errors and warnings)
- print each pair of:
- expression
- error, or result with possible warning(s)

It works reasonably quick for small chunks, but that is ok for my purposes.

I hope it helps anyone. Should there be better alternatives, I would be
more than grateful for a hint.

Best,
Adrian

On Mon, Sep 5, 2016 at 5:33 PM, Bert Gunter <bgunter.4...@gmail.com> wrote:

> I'm sharing this with r-help, as your detailed response might help
> others help you.
>
> -- Bert
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Sun, Sep 4, 2016 at 11:45 PM, Adrian Dușa <dusa.adr...@unibuc.ro>
> wrote:
> > On Mon, Sep 5, 2016 at 2:52 AM, Bert Gunter <bgunter.4...@gmail.com>
> wrote:
> >>
> >> You might want to look at the "evaluate" package.
> >
> >
> > Of course, forgot to mention. I did try it, but got:
> >
> >> bar <- readLines("foo.R", warn = FALSE)
> >> bar <- paste(bar, collapse = "\n")
> >> evaluate::evaluate(input = bar)
> > [[1]]
> > $src
> > [1] "foo <- function(x) {\nprint(x)\n}\nprint)foo)\nfoo(2)"
> >
> > attr(,"class")
> > [1] "source"
> >
> > [[2]]
> > :4:6: unexpected ')'
> > 3: }
> > 4: print)
> > ^>
> >
> > I ran into the same problem as source(): it works only if it doesn't have
> > any errors. In addition, the error message is also different because it
> > evaluates the entire chunk, whereas the R console evaluates one command
> > (line) at a time.
> >
> > Fixing the command:
> > bar2 <- "foo <- function(x) {\nprint(x)\n}\nprint(foo)\nfoo(2)"
> >
> > will fix the workflow in evaluate():
> >
> > evaluate::evaluate(input = bar2)
> >
> >
> > But it will also fix it with source():
> >
> >> source("foo2.R", echo = TRUE, keep.source = TRUE)
> >
> >> foo <- function(x) {
> > + print(x)
> > + }
> >
> >> print(foo)
> > function(x) {
> > print(x)
> > }
> >
> >> foo(2)
> > [1] 2
> >
> >
> > So evaluate() has more detail than source(), but essentially they do the
> > same thing in evaluating the whole chunk. From the help of source():
> > "Since the complete file is parsed before any of it is run, syntax errors
> > result in none of the code being run."
> >
> > So far, it seems that only R CMD BATCH is able to run one command at a
> time:
> >
> > $ R CMD BATCH -q foo.R
> > $ cat foo.Rout
> >> foo <- function(x) {
> > + print(x)
> > + }
> >> print)foo)
> > Error: unexpected ')' in "print)"
> > Execution halted
> >
> > This error is exactly the same as in the R console, and the function
> foo()
> > is created before the error occurs. One possible solution is to get the
> > workspace saved, and run R CMD BATCH again on the rest of commands after
> the
> > error.
> >
> > But it still needs additional objects if the chunk is to be evaluated in
> a
> > specific environment. This is the point where I've got, and I don't know
> if
> > this is the best approach.
> >
> > Thank you,
> > Adrian
>


-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] evaluating expressions as R console

2016-09-05 Thread Adrian Dușa
On Mon, Sep 5, 2016 at 5:33 PM, Bert Gunter  wrote:
>
> I'm sharing this with r-help, as your detailed response might help
> others help you.


Oh, my bad (thought I had replied to all).
I wanted to add anyways the intended result seems to be possible. If
pasting the code here...:
http://www.tutorialspoint.com/r_terminal_online.php

... the result is exactly as in the R console.

Maybe this is a different technology (direct websocket?), but if they are
evaluating the text they're doing a very good job.

Best,
Adrian

--
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] evaluating expressions as R console

2016-09-04 Thread Adrian Dușa
Dear R users,

I am trying to simulate a pseudo R console, evaluating commands. This is a
simple example of a series of command lines which get evaluated:

foo <- function(x) {
print(x)
}
print)foo)
foo(2)


If I copied and pasted this example in an R console, this is the result to
replicate (and the benchmark to compare everything else):

> foo <- function(x) {
+ print(x)
+ }
> print)foo)
Error: unexpected ')' in "print)"
> foo(2)
[1] 2


The trouble I'm having is to reproduce this exact output, by evaluating the
chunk of code. I tried both Rscript and littler, but I am unable to
reproduce this.

I had some success via:

R CMD BATCH -q foo.R

(saving the chunk to a file called foo.R), which only works until the first
error appears. I can run it again on the subsequent command(s) after the
error, but the function foo(), which in a normal R console gets created
without any error, doesn't get preserved on the next run.

I also had some limited success with:

source("foo.R", echo = TRUE, keep.source = TRUE)

But the error message is different, and the first 4 lines are not echo-ed.

source() works pretty well if there are no errors, but otherwise I get the
same result as R CMD BATCH, namely only the error is displayed and the
function foo() doesn't get created in the current environment.

I would rather use source() than R CMD BATCH, due to specific environments
where the chunk should be evaluated in (not impossible, but inconvenient to
save environments and load them back in the R CMD BATCH).

Was also curious about knitr and pander, but again unable to replicate the
results in the real R console.

After many hours of searching, reading and testing, I would be grateful for
any hint.

Thank you in advance,
Adrian

-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Importing data from a text file with no separator

2016-06-08 Thread Adrian Dușa
See:
?read.fwf

Example:
> ff <- tempfile()
> cat(file = ff, "10030614911608", "10030614911608", sep =
"\n")

> read.fwf(ff, widths = c(2,8,10), colClasses = "character")
  V1   V2 V3
1 10 03061490 000116
2 10 03061490 000116

> unlink(ff)

Hth,
Adrian


On Thu, Jun 9, 2016 at 3:40 AM, Paolo Letizia 
wrote:

> I have row data in a text file, where each row consists of 22 numerical
> characters. Each row consists of three different column but there is no
> separator. Specifically, the first two characters of the raw represent  the
> first column of data, the subsequent 8 characters represent the second
> column of data and the last 12 characters represent the third column of
> data. An example follows:
>
> row data:
> 10030614911608
>
> The first two characters, "10", is the column "Regime"; the subsequent 8
> characters, "03061490", is the column "Industry", and the last 12
> characters, "00011608", is the column dollar value. How do I import the
> column data into R without having any separator in the text file?
> Thanks for your help, Paolo.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>



-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Bug in by() function which works for some FUN argument and does not work for others

2016-04-14 Thread Adrian Dușa
I think you are not using the best function for what your intentions are.
Try:

> by(data=mtcars, INDICES=list(as.factor(mtcars$am)), FUN=colMeans)
: 0
mpg cyldisp  hpdrat  wt
   qsec  vs
 17.1473684   6.9473684 290.3789474 160.2631579   3.2863158   3.7688947
 18.1831579   0.3684211
 amgearcarb
  0.000   3.2105263   2.7368421
---
: 1
mpg cyldisp  hpdrat  wt
   qsec  vs
 24.3923077   5.0769231 143.5307692 126.8461538   4.050   2.411
 17.360   0.5384615
 amgearcarb
  1.000   4.3846154   2.9230769

See the difference between colMeans() and mean() in their respective help
files.
Hth,
Adrian

On Thu, Apr 14, 2016 at 11:14 PM, Akhilesh Singh <
akhileshsingh.i...@gmail.com> wrote:

> Dear Sirs,
>
> I am Professor at Indira Gandhi Krishi Vishwavidyalaya, Raipur,
> Chhattisgarh, India.
>
> While taking classes, I found the *by() *function producing following error
> when I use FUN=mean or median and some other functions, however,
> FUN=summary works.
>
> Given below is the output of the example I used on a built-in dataset
> "mtcars", along with error message reproduced herewith:
>
> > by(data=mtcars, INDICES=list(mtcars$am), FUN=mean)
> : 0
> [1] NA
> 
> : 1
> [1] NA
> Warning messages:
> 1: In mean.default(data[x, , drop = FALSE], ...) :
>   argument is not numeric or logical: returning NA
> 2: In mean.default(data[x, , drop = FALSE], ...) :
>   argument is not numeric or logical: returning NA
>
> However, the same by() function works for FUN=summary, given below is the
> output:
>
> > by(data=mtcars, INDICES=list(mtcars$am), FUN=summary)
> : 0
>   mpg cyl disp hp
>  Min.   :10.40   Min.   :4.000   Min.   :120.1   Min.   : 62.0
>  1st Qu.:14.95   1st Qu.:6.000   1st Qu.:196.3   1st Qu.:116.5
>  Median :17.30   Median :8.000   Median :275.8   Median :175.0
>  Mean   :17.15   Mean   :6.947   Mean   :290.4   Mean   :160.3
>  3rd Qu.:19.20   3rd Qu.:8.000   3rd Qu.:360.0   3rd Qu.:192.5
>  Max.   :24.40   Max.   :8.000   Max.   :472.0   Max.   :245.0
>   drat wt qsec vs   am
>
>  Min.   :2.760   Min.   :2.465   Min.   :15.41   Min.   :0.   Min.   :0
>
>  1st Qu.:3.070   1st Qu.:3.438   1st Qu.:17.18   1st Qu.:0.   1st Qu.:0
>
>  Median :3.150   Median :3.520   Median :17.82   Median :0.   Median :0
>
>  Mean   :3.286   Mean   :3.769   Mean   :18.18   Mean   :0.3684   Mean   :0
>
>  3rd Qu.:3.695   3rd Qu.:3.842   3rd Qu.:19.17   3rd Qu.:1.   3rd Qu.:0
>
>  Max.   :3.920   Max.   :5.424   Max.   :22.90   Max.   :1.   Max.   :0
>
>   gearcarb
>  Min.   :3.000   Min.   :1.000
>  1st Qu.:3.000   1st Qu.:2.000
>  Median :3.000   Median :3.000
>  Mean   :3.211   Mean   :2.737
>  3rd Qu.:3.000   3rd Qu.:4.000
>  Max.   :4.000   Max.   :4.000
> 
> : 1
>   mpg cyl disp hp drat
>
>  Min.   :15.00   Min.   :4.000   Min.   : 71.1   Min.   : 52.0   Min.
> :3.54
>  1st Qu.:21.00   1st Qu.:4.000   1st Qu.: 79.0   1st Qu.: 66.0   1st
> Qu.:3.85
>  Median :22.80   Median :4.000   Median :120.3   Median :109.0   Median
> :4.08
>  Mean   :24.39   Mean   :5.077   Mean   :143.5   Mean   :126.8   Mean
> :4.05
>  3rd Qu.:30.40   3rd Qu.:6.000   3rd Qu.:160.0   3rd Qu.:113.0   3rd
> Qu.:4.22
>  Max.   :33.90   Max.   :8.000   Max.   :351.0   Max.   :335.0   Max.
> :4.93
>wt qsec vs   am gear
>
>  Min.   :1.513   Min.   :14.50   Min.   :0.   Min.   :1   Min.   :4.000
>
>  1st Qu.:1.935   1st Qu.:16.46   1st Qu.:0.   1st Qu.:1   1st Qu.:4.000
>
>  Median :2.320   Median :17.02   Median :1.   Median :1   Median :4.000
>
>  Mean   :2.411   Mean   :17.36   Mean   :0.5385   Mean   :1   Mean   :4.385
>
>  3rd Qu.:2.780   3rd Qu.:18.61   3rd Qu.:1.   3rd Qu.:1   3rd Qu.:5.000
>
>  Max.   :3.570   Max.   :19.90   Max.   :1.   Max.   :1   Max.   :5.000
>
>   carb
>  Min.   :1.000
>  1st Qu.:1.000
>  Median :2.000
>  Mean   :2.923
>  3rd Qu.:4.000
>  Max.   :8.000
> >
>
> I am using the latest version of *R-3.2.4 on Windows*, however, this error
> is being generated in the previous version too,
>
> Hope this reporting will get serious attention in debugging.
>
> With best regards,
>
> Dr. A.K. Singh
> Head, Department of Agril. Statistics
> Indira Gandhi Krishi Vishwavidyalaya, Raipur
> Chhattisgarh, India, PIN-492012
> Mobile: +919752620740
> Email: akhileshsingh.i...@gmail.com
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and 

Re: [R] formula argument evaluation

2016-04-14 Thread Adrian Dușa
Thanks Bill, it's very useful to know how parsing and evaluation works.
It seems that quoting is the least complicated solution which is guaranteed
to work.

Best,
Adrian
On 13 Apr 2016 6:04 p.m., "William Dunlap" <wdun...@tibco.com> wrote:

> %=>% would have precendence ('order of operations') problems also.
>
>A + B %=>% C
>
> is equivalent to
>
>   A + ( B %=>% C)
>
> and I don't think that is what you want.
>
> as.list(quote(A + B %=>% C)) shows the first branch in the parse tree.
> The following function, str.language, shows the entire parse tree, as in
>
>   > str.language(quote(A + B %=>% C))
>   `quote(A + B %=>% C)` call(3): A + B %=>% C
> `` name(1): +
> `` name(1): A
> `` call(3): B %=>% C
>   `` name(1): %=>%
>   `` name(1): B
>   `` name(1): C
>
> str.language <-
> function (object, ..., level = 0, name = myDeparse(substitute(object)))
> {
> abbr <- function(string, maxlen = 25) {
> if (length(string) > 1 || nchar(string) > maxlen)
> paste(substring(string[1], 1, maxlen), "...", sep = "")
> else string
> }
> myDeparse <- function(object) {
> if (!is.environment(object)) {
> deparse(object)
> }
> else {
> ename <- environmentName(object)
> if (ename == "")
> ename <- ""
> paste(sep = "", "<", ename, "> ", paste(collapse = " ",
> objects(object)))
> }
> }
> cat(rep("  ", level), sep = "")
> if (is.null(name))
> name <- ""
> cat(sprintf("`%s` %s(%d): %s\n", abbr(name), class(object),
> length(object), abbr(myDeparse(object
> a <- attributes(object)
> if (is.recursive(object) && !is.environment(object)) {
> object <- as.list(object)
> names <- names(object)
> for (i in seq_along(object)) {
>     str.language(object[[i]], ..., level = level + 1,
> name = names[i])
> }
> }
> a$names <- NULL
> if (length(a) > 0) {
> str.language(a, level = level + 1, name = paste("Attributes of",
> abbr(name)))
> }
> }
>
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> On Tue, Apr 12, 2016 at 11:59 PM, Adrian Dușa <dusa.adr...@unibuc.ro>
> wrote:
>
>> I suppose it would work, although "=>" is rather a descriptive symbol and
>> less a function.
>> But choosing between quoting:
>> "A + B => C"
>> and a regular function:
>> A + B %=>% C
>> probably quoting is the most straightforward, as the result of the foo()
>> function has to be a string anyways (which is parsed by other functions).
>>
>> On Tue, Apr 12, 2016 at 6:20 PM, Richard M. Heiberger <r...@temple.edu>
>> wrote:
>>
>> > Would making it regular function %=>%, using "%" instead of quotes,
>> > work for you?
>> >
>> > On Tue, Apr 12, 2016 at 11:09 AM, Adrian Dușa <dusa.adr...@unibuc.ro>
>> > wrote:
>> > > On Tue, Apr 12, 2016 at 2:08 PM, Duncan Murdoch <
>> > murdoch.dun...@gmail.com>
>> > > wrote:
>> > >> [...]
>> > >>
>> > >> It never gets to evaluating it.  It is not a legal R statement, so
>> the
>> > > parser signals an error.
>> > >> If you want to pass arbitrary strings to a function, you need to put
>> > them
>> > > in quotes.
>> > >
>> > > I see. I thought it was parsed inside the function, but if it's parsed
>> > > before then quoting is the only option.
>> > >
>> > >
>> > > To Keith: no, I mean it like this "A + B => C" which is translated as:
>> > > "the union of A and B is sufficient for C" in set theoretic language.
>> > >
>> > > The "=>" operator means sufficiency, while "<=" means necessity.
>> Quoting
>> > > the expression is good enough, I was just curious if the quotes could
>> be
>> > > made redundant, somehow.
>> > >
>> > > Thank you both,
>> > > Adrian
>> > >
>> > > --
>> > > Adrian Dusa
>> > > University of Bucharest
>> > > Romanian Social Data Archive
>> > >

Re: [R] formula argument evaluation

2016-04-13 Thread Adrian Dușa
I suppose it would work, although "=>" is rather a descriptive symbol and
less a function.
But choosing between quoting:
"A + B => C"
and a regular function:
A + B %=>% C
probably quoting is the most straightforward, as the result of the foo()
function has to be a string anyways (which is parsed by other functions).

On Tue, Apr 12, 2016 at 6:20 PM, Richard M. Heiberger <r...@temple.edu>
wrote:

> Would making it regular function %=>%, using "%" instead of quotes,
> work for you?
>
> On Tue, Apr 12, 2016 at 11:09 AM, Adrian Dușa <dusa.adr...@unibuc.ro>
> wrote:
> > On Tue, Apr 12, 2016 at 2:08 PM, Duncan Murdoch <
> murdoch.dun...@gmail.com>
> > wrote:
> >> [...]
> >>
> >> It never gets to evaluating it.  It is not a legal R statement, so the
> > parser signals an error.
> >> If you want to pass arbitrary strings to a function, you need to put
> them
> > in quotes.
> >
> > I see. I thought it was parsed inside the function, but if it's parsed
> > before then quoting is the only option.
> >
> >
> > To Keith: no, I mean it like this "A + B => C" which is translated as:
> > "the union of A and B is sufficient for C" in set theoretic language.
> >
> > The "=>" operator means sufficiency, while "<=" means necessity. Quoting
> > the expression is good enough, I was just curious if the quotes could be
> > made redundant, somehow.
> >
> > Thank you both,
> > Adrian
> >
> > --
> > Adrian Dusa
> > University of Bucharest
> > Romanian Social Data Archive
> > Soseaua Panduri nr.90
> > 050663 Bucharest sector 5
> > Romania
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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.
>



-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] formula argument evaluation

2016-04-12 Thread Adrian Dușa
On Tue, Apr 12, 2016 at 2:08 PM, Duncan Murdoch 
wrote:
> [...]
>
> It never gets to evaluating it.  It is not a legal R statement, so the
parser signals an error.
> If you want to pass arbitrary strings to a function, you need to put them
in quotes.

I see. I thought it was parsed inside the function, but if it's parsed
before then quoting is the only option.


To Keith: no, I mean it like this "A + B => C" which is translated as:
"the union of A and B is sufficient for C" in set theoretic language.

The "=>" operator means sufficiency, while "<=" means necessity. Quoting
the expression is good enough, I was just curious if the quotes could be
made redundant, somehow.

Thank you both,
Adrian

--
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] formula argument evaluation

2016-04-12 Thread Adrian Dușa
I have a simple function such as:

foo <- function(x) {
call <- lapply(match.call(), deparse)
testit <- capture.output(tryCatch(eval(x), error = function(e) e))
if (grepl("Error", testit)) {
return(call$x)
}
}

and I would like to detect a formula when x is not an object:

# this works
> foo(A + B)
[1] "A + B"

# but this doesn't
> foo(A + B => C)
Error: unexpected '=' in "foo(A + B ="

Can I prevent it from evaluating the "=" sign?
The addition sign "+" hasn't been evaluated, and I was hoping the "=" would
not get evaluated either. The "=>" sign is important for other purposes,
not related to this example.

Thank you in advance,
Adrian

--
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] sorting of files using system

2016-04-09 Thread Adrian Dușa
I suspect it is a problem related to locales: R and the base Ubuntu might
be using different locales, hence the source of the different sorting.
Can't say if this is the problem in your case, but it might be.
Adrian

On Sat, Apr 9, 2016 at 12:18 AM, Maria Ninova  wrote:

> Hello, I came across the following oddity when it comes to file order
> using the system command: different system commands return files in a
> different order:
> This is a real filenames example:
>
> > system("ls gw1kb_tables/rpkm_47*", intern=T)
> [1] "gw1kb_tables/rpkm_479_Input.tab"
> [2] "gw1kb_tables/rpkm_479_IP.tab"
>
> > system("for file in gw1kb_tables/rpkm_4*; do echo $file;done" )
> gw1kb_tables/rpkm_479_IP.tab
> gw1kb_tables/rpkm_479_Input.tab
>
> As you see, in the first case, the "Input" comes first, while in the
> second, the IP comes first; I was surprised by this result and not sure if
> it's expected?
> I am using R version 3.2.2 (2015-08-14) on Ubuntu 15.04
>
> Thank you in advance,
>
> Maria
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>



-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Problem with <= (less than or equal): not giving the expected result

2016-04-05 Thread Adrian Dușa
Yes, that does have to do with floating point representation.
I use this function for these types of comparisons (works with values as
well as with vectors):

check.equal <- function(x, y) {
check.vector <- as.logical(unlist(lapply(x, all.equal, y)))
check.vector[is.na(check.vector)] <- FALSE
return(check.vector)
}

See:
?all.equal

Hth,
Adrian

On Tue, Apr 5, 2016 at 2:34 PM, Rainer Johannes 
wrote:

> Dear All,
>
> I have the following problem:
>
> I have a function in which I check if the difference between values is
> smaller or equal to a certain threshold. I however realized that I might
> get there some unexpected results:
>
> > abs(1 - 0.95) >= 0.05
> [1] TRUE
> ## So that’s fine, but:
> > abs(1 - 0.95) <= 0.05
> [1] FALSE
>
> Apparently, abs(1 - 0.95) is not equal to 0.05, which I find however quite
> disturbing.
>
> Along these lines:
> > abs(0.95 - 1) > 0.05
> [1] TRUE
> > abs(0.95 - 1) < 0.05
> [1] FALSE
>
> I guess that has to do with the floating point representation of the data?
>
> Is there something I miss or is there any solution to this?
> Thanks for any help!
>
> cheers, jo
>
>
>
> I tried this on different R-version (including 3.2.3 and 3.3.0 alpha); The
> R-version I used for the code above is:
>
> > sessionInfo()
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-unknown-linux-gnu (64-bit)
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>  [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
>  [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
>  [9] LC_ADDRESS=C   LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.




-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] How to create an executable file from R GUI?

2016-02-22 Thread Adrian Dușa
It doesn't look like HTML because it is not HTML at all, it is actually SVG.
I found that creating exact locations for checkboxes, radios and text,
using raw HTML, is a pain, therefore I created my own library of functions
which combines SVG and Javascript.
The graphs are also SVG, although I am looking to embed normal R graphics
via shiny.

On Mon, Feb 22, 2016 at 1:22 PM, Dmitri Popavenko <
dmitri.popave...@gmail.com> wrote:

> That is a very nice interface, indeed!
> What kind of HTML you used for this interface, it is looking different
> from the normal.
>
> On Sun, Feb 21, 2016 at 11:37 AM, Adrian Dușa <dusa.adr...@unibuc.ro>
> wrote:
>
>> Oh, thanks Peter, good example for Mac, but indeed not working on Windows.
>> For a completely cross-platform solution (that is, including Windows which
>> is what Zahra wants), I believe shiny is the right tool.
>>
>> So Zahra, if you want to use shiny, you need to look at their own
>> tutorials, step by step, and try to understand how it works.
>> They have predefined tools to make "apps", which can be deployed either
>> locally or on a web server. But you will be dependent on the available
>> shiny toolkit.
>> Otherwise, if you want to make a completely customized interface, you need
>> to use a combination of R, HTML and Javascript.
>>
>> Take a look at the GUI from the QCAGUI package (download the sources, it's
>> in the "inst" directory): it can read the local filesystem, import /
>> export
>> data, it does various data transformations and various QCA related
>> analyses
>> and graphs.
>> Everything is highly customized, with drop-down menus and pop-up dialogs,
>> including an output one which mimics the R console.
>> To look at the interface, type:
>>
>> library(QCAGUI)
>> runGUI()
>>
>> I hope it helps,
>> Adrian
>
>
>


-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] How to create an executable file from R GUI?

2016-02-21 Thread Adrian Dușa
Oh, thanks Peter, good example for Mac, but indeed not working on Windows.
For a completely cross-platform solution (that is, including Windows which
is what Zahra wants), I believe shiny is the right tool.

So Zahra, if you want to use shiny, you need to look at their own
tutorials, step by step, and try to understand how it works.
They have predefined tools to make "apps", which can be deployed either
locally or on a web server. But you will be dependent on the available
shiny toolkit.
Otherwise, if you want to make a completely customized interface, you need
to use a combination of R, HTML and Javascript.

Take a look at the GUI from the QCAGUI package (download the sources, it's
in the "inst" directory): it can read the local filesystem, import / export
data, it does various data transformations and various QCA related analyses
and graphs.
Everything is highly customized, with drop-down menus and pop-up dialogs,
including an output one which mimics the R console.
To look at the interface, type:

library(QCAGUI)
runGUI()

I hope it helps,
Adrian

On Sat, Feb 20, 2016 at 2:46 PM, peter dalgaard <pda...@gmail.com> wrote:

> It's quite platform dependent, but this idea works for tcl/tk on Mac. I
> don't think it would be too hard to do similar things on Linux, Windows may
> be a bigger challenge (or not).
>
> Peter-Dalgaards-MacBook-Air:tmp pd$ cat foo.app
> #!/usr/bin/Rscript
> library(tcltk)
> demo(tkfaq)
> tkwait.variable("exit")
>
> Make it executable (chmod +x foo.app) and you can double-click it in the
> Finder. (Notice that as written, there is nothing to shut down the tkwait
> loop, so you'll have to force quit it.)
>
> Peter D.
>
> > On 19 Feb 2016, at 23:36 , Adrian Dușa <dusa.adr...@unibuc.ro> wrote:
> >
> > Your function, buildGui(), what does it use, Tcl/Tk or something else?
> > If it's Tcl/Tk, I believe you need a normal R console opened. My .bat
> file
> > only works for a command line, which is fine if the user interface opens
> up
> > in a webpage, but I'm pretty sure it doesn\t work with Tcl/Tk.
> > What kind of window does your function return?
> > Adrian
> >
> > On Fri, Feb 19, 2016 at 4:35 PM, Zahra Samadi <simon0...@yahoo.com>
> wrote:
> >
> >> Adriana,
> >> My GUI file is a function returning a window. This function is named
> >> buildGui(). How should I create this batch file using the piece of code
> >> you've written?
> >>
> >> --
> >> * From: * Adrian Dușa <dusa.adr...@unibuc.ro>;
> >> * To: * Greg Snow <538...@gmail.com>;
> >> * Cc: * simon0...@yahoo.com <simon0...@yahoo.com>; r-help@r-project.org
> <
> >> r-help@r-project.org>;
> >> * Subject: * Re: [R] How to create an executable file from R GUI?
> >> * Sent: * Thu, Feb 18, 2016 9:03:52 PM
> >>
> >> Simon, Greg,
> >>
> >> That is the very reason why I've given up on Tck/Tk, in favor of shiny.
> >> The user interface opens up in a webpage, without opening the normal R
> >> console (it only opens a Terminal window).
> >>
> >> To exemplify, package QCAGUI has a function called runGUI(), and on
> >> Windows it's a simple matter of creating a .bat file,
> >> which for my user interface it only contains this:
> >>
> >> CLS
> >>
> >> TITLE QCA Qualitative Comparative Analysis
> >>
> >> C:/PROGRA~1/R/R-3.2.3/bin/R.exe --slave --no-restore -e
> >> "setwd('D:/');QCAGUI::runGUI()"
> >>
> >>
> >> The double click on the .bat file, and that's it.
> >> I hope it helps,
> >> Adrian
> >>
> >>
> >>
> >> On Thu, Feb 18, 2016 at 7:24 PM, Greg Snow <538...@gmail.com> wrote:
> >>
> >>> To give a full answer we need some more detail from you.  For example
> >>> what operating system are you on? what do you mean by "users click on
> >>> it"? and at what point do you want them to click (after running R,
> >>> when looking at the desktop, etc.)
> >>>
> >>> But to help get you started you may want to look at the help page
> >>> `?Startup` which tells you all the things that R does as it starts up
> >>> and how to have it run commands automatically as it is starting up.
> >>>
> >>> I have created some GUI examples in the past that clients then wanted
> >>> to have on their own computer to play with and demonstrate to others.
> >>> I usually would install R on their machine for them and create a
> >>

Re: [R] How to create an executable file from R GUI?

2016-02-20 Thread Adrian Dușa
I don't know about RGtk2, never tried it, but I assume it is similar to
Tcl/Tk situation: you need to open an R console to make it work.
My approach works, only because I am using the package shiny, and R's web
server can be started via a script in the terminal.
I might be wrong of course, but I haven't been able to start a GUI from a
script, other than using a webpage,

Package shiny is very nice, and since it can be started with a script, it
means that one can also use the normal R console in parallel, if needed.
Otherwise, if started from the R console, R will be busy listening to the
web server: it's either R, or the GUI, but not both in the same time.


On Sat, Feb 20, 2016 at 8:50 AM, Zahra Samadi  wrote:

> My function returns a RGtk2 window. It's not important if my GUI opens in
> a browser, I just want to have a file that when clicked, my GUI opens.
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>



-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] How to create an executable file from R GUI?

2016-02-19 Thread Adrian Dușa
Your function, buildGui(), what does it use, Tcl/Tk or something else?
If it's Tcl/Tk, I believe you need a normal R console opened. My .bat file
only works for a command line, which is fine if the user interface opens up
in a webpage, but I'm pretty sure it doesn\t work with Tcl/Tk.
What kind of window does your function return?
Adrian

On Fri, Feb 19, 2016 at 4:35 PM, Zahra Samadi <simon0...@yahoo.com> wrote:

> Adriana,
> My GUI file is a function returning a window. This function is named
> buildGui(). How should I create this batch file using the piece of code
> you've written?
>
> ------
> * From: * Adrian Dușa <dusa.adr...@unibuc.ro>;
> * To: * Greg Snow <538...@gmail.com>;
> * Cc: * simon0...@yahoo.com <simon0...@yahoo.com>; r-help@r-project.org <
> r-help@r-project.org>;
> * Subject: * Re: [R] How to create an executable file from R GUI?
> * Sent: * Thu, Feb 18, 2016 9:03:52 PM
>
> Simon, Greg,
>
> That is the very reason why I've given up on Tck/Tk, in favor of shiny.
> The user interface opens up in a webpage, without opening the normal R
> console (it only opens a Terminal window).
>
> To exemplify, package QCAGUI has a function called runGUI(), and on
> Windows it's a simple matter of creating a .bat file,
> which for my user interface it only contains this:
>
> CLS
>
> TITLE QCA Qualitative Comparative Analysis
>
> C:/PROGRA~1/R/R-3.2.3/bin/R.exe --slave --no-restore -e
> "setwd('D:/');QCAGUI::runGUI()"
>
>
> The double click on the .bat file, and that's it.
> I hope it helps,
> Adrian
>
>
>
> On Thu, Feb 18, 2016 at 7:24 PM, Greg Snow <538...@gmail.com> wrote:
>
>> To give a full answer we need some more detail from you.  For example
>> what operating system are you on? what do you mean by "users click on
>> it"? and at what point do you want them to click (after running R,
>> when looking at the desktop, etc.)
>>
>> But to help get you started you may want to look at the help page
>> `?Startup` which tells you all the things that R does as it starts up
>> and how to have it run commands automatically as it is starting up.
>>
>> I have created some GUI examples in the past that clients then wanted
>> to have on their own computer to play with and demonstrate to others.
>> I usually would install R on their machine for them and create a
>> shortcut on the desktop (these were all MS Windows computers) that
>> pointed to the standard R executable, but started in a specific
>> directory/folder.  Then in that folder I created a ".Rprofile" file
>> with the commands to load in the appropriate data and packages and run
>> the gui demonstration.  The user could then double click on the
>> shortcut on the desktop and 2 windows would pop up (the regular R
>> interface and my gui demo), I instructed the client to just minimize
>> and ignore the regular R window and they were then able to use my demo
>> and then close everything when they were finished.  You could do
>> something similar (but exactly how will differ between Windows, Mac,
>> and Linux computers).
>>
>> On Thu, Feb 18, 2016 at 9:27 AM, simon0098--- via R-help
>> <r-help@r-project.org> wrote:
>> > Hi,
>> > I've created a GUI using RGtk2 package. How can I make an executable
>> file from my R script so that users click on it and the GUI appears for
>> them?
>> >
>> >
>> > [[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > 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.
>>
>>
>>
>> --
>> Gregory (Greg) L. Snow Ph.D.
>> 538...@gmail.com
>>
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>>
>>
>
>
> --
> Adrian Dusa
> University of Bucharest
> Romanian Social Data Archive
> Soseaua Panduri nr.90
> 050663 Bucharest sector 5
> Romania
>



-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] How to create an executable file from R GUI?

2016-02-18 Thread Adrian Dușa
Simon, Greg,

That is the very reason why I've given up on Tck/Tk, in favor of shiny.
The user interface opens up in a webpage, without opening the normal R
console (it only opens a Terminal window).

To exemplify, package QCAGUI has a function called runGUI(), and on Windows
it's a simple matter of creating a .bat file,
which for my user interface it only contains this:

CLS

TITLE QCA Qualitative Comparative Analysis

C:/PROGRA~1/R/R-3.2.3/bin/R.exe --slave --no-restore -e
"setwd('D:/');QCAGUI::runGUI()"


The double click on the .bat file, and that's it.
I hope it helps,
Adrian



On Thu, Feb 18, 2016 at 7:24 PM, Greg Snow <538...@gmail.com> wrote:

> To give a full answer we need some more detail from you.  For example
> what operating system are you on? what do you mean by "users click on
> it"? and at what point do you want them to click (after running R,
> when looking at the desktop, etc.)
>
> But to help get you started you may want to look at the help page
> `?Startup` which tells you all the things that R does as it starts up
> and how to have it run commands automatically as it is starting up.
>
> I have created some GUI examples in the past that clients then wanted
> to have on their own computer to play with and demonstrate to others.
> I usually would install R on their machine for them and create a
> shortcut on the desktop (these were all MS Windows computers) that
> pointed to the standard R executable, but started in a specific
> directory/folder.  Then in that folder I created a ".Rprofile" file
> with the commands to load in the appropriate data and packages and run
> the gui demonstration.  The user could then double click on the
> shortcut on the desktop and 2 windows would pop up (the regular R
> interface and my gui demo), I instructed the client to just minimize
> and ignore the regular R window and they were then able to use my demo
> and then close everything when they were finished.  You could do
> something similar (but exactly how will differ between Windows, Mac,
> and Linux computers).
>
> On Thu, Feb 18, 2016 at 9:27 AM, simon0098--- via R-help
>  wrote:
> > Hi,
> > I've created a GUI using RGtk2 package. How can I make an executable
> file from my R script so that users click on it and the GUI appears for
> them?
> >
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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.
>
>
>
> --
> Gregory (Greg) L. Snow Ph.D.
> 538...@gmail.com
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>



-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] missing values in csv file

2016-02-17 Thread Adrian Dușa
On Wed, Feb 17, 2016 at 12:04 PM, Jan Kacaba  wrote:

> In my original data a csv file I have missing values. If I use read.table
> the missing values are replaced by NAs.
>

That is the normal way of dealing with missing values, in R.


Is it possible to get object where missing values aren't replaced with NAs?
> Is it possible to replace NAs with empty space?
>

It is possible to replace the NAs with empty space, but nobody would
recommend that because your variable will be coerced to a character mode.
If the other values are numbers, you won't be able to compute any numerical
measures.
Try to accept that NA is there for a reason, in R.

I hope this helps,
Adrian

-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Split Strings

2016-01-17 Thread Adrian Dușa
Try this:

mylist <- list("pc_m2_45_ssp3_wheat", "pc_m2_45_ssp3_wheat", "ssp3_maize",
"m2_wheat")
mylist <- lapply(mylist, function(x) unlist(strsplit(x, split="_")))
allstrings <- unique(unlist(mylist))
lapply(mylist, function(x) allstrings[match(allstrings, x)])

[[1]]
[1] "pc""m2""45""ssp3"  "wheat" NA

[[2]]
[1] "pc""m2""45""ssp3"  "wheat" NA

[[3]]
[1] NA   NA   NA   "pc" NA   "m2"

[[4]]
[1] NA   "pc" NA   NA   "m2" NA

Hope this helps,
Adrian

On Sun, Jan 17, 2016 at 10:56 PM, Miluji Sb  wrote:

> I have a list of strings of different lengths and would like to split each
> string by underscore "_"
>
> pc_m2_45_ssp3_wheat
> pc_m2_45_ssp3_wheat
> ssp3_maize
> m2_wheat
>
> I would like to separate each part of the string into different columns
> such as
>
> pc m2 45 ssp3 wheat
>
> But because of the different lengths - I would like NA in the columns for
> the variables have fewer parts such as
>
> NA NA NA m2 wheat
>
> I have tried unlist(strsplit(x, "_")) to split, it works for one variable
> but not for the list - gives me "non-character argument" error. I would
> highly appreciate any help. Thank you!
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>



-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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-pkgs] new package: venn

2016-01-11 Thread Adrian Dușa
Dear R users,

I would like to announce a new package that has just the appeared on CRAN,
called "venn" version 1.0:
http://cran.r-project.org/web/packages/venn/
(binaries will appear in one or two days)

Although there are quite a few packages that draw Venn diagrams, there are
a number of reasons for yet another one:

- this package draws diagrams up to 7 sets (!) while other packages top at 5

- in addition, this package is also capable to draw any boolean union of
set intersections, using different colors (transparency included), using a
meta-command

- efforts were employed to create these diagrams using base R, without
using any dependencies to other graphics oriented packages

- there are a variety of input data which are automatically recognised,
making the package user friendly

- the technology behind this package is completely different from the other
Venn diagrams functions, similar to geographical maps where polygons can be
constructed on a hierarchical order, the way administrative units belong to
superior, higher units.

The most impressive diagram to show off is the so-called "Adelaide" for 7
sets, which can be viewed simply with:

> venn(7)

Comments and suggestions are, as always, welcome.

Best wishes,
Adrian

--
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Bezier to line segments

2016-01-09 Thread Adrian Dușa
Thanks Greg, I'll take a look on that package as well.
I'm still unsure whether to calculate these splines at each function run,
or to store the coordinates of each spline (curve) and read them when
needed. There are performance issues to take into account, but from my
current tests it seems that calculating the coordinates each time decreases
timing performance.

For the moment I opted to store the values, but if I will find a quick(er)
alternative, will change it at the next version.

This is for a new package called venn (now on CRAN), to which I am going to
send an announcement to r-packages.

Best wishes,
Adrian



On Thu, Jan 7, 2016 at 6:54 PM, Greg Snow <538...@gmail.com> wrote:

> You may also be interested in the xspline function (graphics package,
> so you don't need to install or load anything extra) since you mention
> general splines.  These splines can be made similar to Bezier curves
> (but not exactly the same).  The function returns a set of coordinates
> (when draw=FALSE) that represent line segments for drawing the
> approximate curve.
>
> On Wed, Jan 6, 2016 at 6:43 AM, Adrian Dușa <dusa.adr...@unibuc.ro> wrote:
> > I just found the package "bezier".
> > Trying to find the needle, I missed the haystack...
> >
> > On Wed, Jan 6, 2016 at 9:56 AM, Adrian Dușa <dusa.adr...@unibuc.ro>
> wrote:
> >
> >> Dear All,
> >>
> >> I am interested into transforming Bezier curves (or general splines) to
> a
> >> series of line segments.
> >> For simplicity, the Bezier curves are either cubic (arches, no
> inflection
> >> points) or they have at most one inflection point.
> >>
> >> The entry parameters are exactly four points (with x and y coordinates):
> >> - start point
> >> - end point
> >> - and two control points to define the curve.
> >>
> >> I read a lot about parabolic approximation, and there is also a famous
> >> deCasteljau algorithm.
> >>
> >> Before attempting to create my own function, I wonder if something like
> >> this already exists in R (or can easily be adapted to R).
> >>
> >> Thanks in advance for any hint,
> >> Adrian
> >>
> >> --
> >> Adrian Dusa
> >> University of Bucharest
> >> Romanian Social Data Archive
> >> Soseaua Panduri nr.90
> >> 050663 Bucharest sector 5
> >> Romania
> >>
> >
> >
> >
> > --
> > Adrian Dusa
> > University of Bucharest
> > Romanian Social Data Archive
> > Soseaua Panduri nr.90
> > 050663 Bucharest sector 5
> > Romania
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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.
>
>
>
> --
> Gregory (Greg) L. Snow Ph.D.
> 538...@gmail.com
>



-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Bezier to line segments

2016-01-06 Thread Adrian Dușa
I just found the package "bezier".
Trying to find the needle, I missed the haystack...

On Wed, Jan 6, 2016 at 9:56 AM, Adrian Dușa <dusa.adr...@unibuc.ro> wrote:

> Dear All,
>
> I am interested into transforming Bezier curves (or general splines) to a
> series of line segments.
> For simplicity, the Bezier curves are either cubic (arches, no inflection
> points) or they have at most one inflection point.
>
> The entry parameters are exactly four points (with x and y coordinates):
> - start point
> - end point
> - and two control points to define the curve.
>
> I read a lot about parabolic approximation, and there is also a famous
> deCasteljau algorithm.
>
> Before attempting to create my own function, I wonder if something like
> this already exists in R (or can easily be adapted to R).
>
> Thanks in advance for any hint,
> Adrian
>
> --
> Adrian Dusa
> University of Bucharest
> Romanian Social Data Archive
> Soseaua Panduri nr.90
> 050663 Bucharest sector 5
> Romania
>



-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Bezier to line segments

2016-01-05 Thread Adrian Dușa
Dear All,

I am interested into transforming Bezier curves (or general splines) to a
series of line segments.
For simplicity, the Bezier curves are either cubic (arches, no inflection
points) or they have at most one inflection point.

The entry parameters are exactly four points (with x and y coordinates):
- start point
- end point
- and two control points to define the curve.

I read a lot about parabolic approximation, and there is also a famous
deCasteljau algorithm.

Before attempting to create my own function, I wonder if something like
this already exists in R (or can easily be adapted to R).

Thanks in advance for any hint,
Adrian

-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] regexp inside and outside brackets

2015-12-11 Thread Adrian Dușa
Thanks very much, Marc and Jeff.
Jeff's solutions seem to be simple one liners. I really need to learn these
things, too powerful to ignore.

Thank you very much,
Adrian

On Fri, Dec 11, 2015 at 5:05 PM, Jeff Newmiller <jdnew...@dcn.davis.ca.us>
wrote:

> The gsub function is your friend.
>
> s <- "A1{0}~B0{1} CO{a2}NN{12}"
> gsub( "([^{}]*)\\{([^{}]*)\\}", "\\1 ", s )
> gsub( "([^{}]*)\\{([^{}]*)\\}", "\\2 ", s )
>
> but keep in mind that there are many resources on the Internet for
> learning about regular expressions... they are hardly R-specific.
>
> --
> Sent from my phone. Please excuse my brevity.
>
> On December 11, 2015 5:50:28 AM PST, "Adrian Dușa" <dusa.adr...@unibuc.ro>
> wrote:
>>
>> For the regexp aficionados, out there:
>>
>> I need a regular expression to extract either everything within some
>> brackets, or everything outside the brackets, in a string.
>>
>> This would be the test string:
>> "A1{0}~B0{1} CO{a2}NN{12}"
>>
>> Everything outside the brackets would be:
>>
>> "A1 ~B0 CO NN"
>>
>> and everything inside the brackets would be:
>>
>> "0 1 a2 12"
>>
>> I have a working solution involving strsplit(), but I wonder if there is a
>> more direct way.
>> Thanks in advance for any hint,
>> Adrian
>>
>>


-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] regexp inside and outside brackets

2015-12-11 Thread Adrian Dușa
For the regexp aficionados, out there:

I need a regular expression to extract either everything within some
brackets, or everything outside the brackets, in a string.

This would be the test string:
"A1{0}~B0{1} CO{a2}NN{12}"

Everything outside the brackets would be:

"A1 ~B0 CO NN"

and everything inside the brackets would be:

"0 1 a2 12"

I have a working solution involving strsplit(), but I wonder if there is a
more direct way.
Thanks in advance for any hint,
Adrian

-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] regexp inside and outside brackets

2015-12-11 Thread Adrian Dușa
Actually, Marc, I think your solution might be more useful than it first
seemed.
The correct usage of a string would be for someone to provide complete
pairs of outside and inside brackets information, like:
A{1} B{0}

But if a user doesn't provide this "standard" notation, as in:
A{1} B

then your solution helps to trap this error and break the function.
It is of course a different problem than my initial email, but it just
struck me that such an error should ideally be trapped.

Many thanks for the useful insight,
Adrian

On Fri, Dec 11, 2015 at 5:29 PM, Marc Schwartz <marc_schwa...@me.com> wrote:

> Hi,
>
> Needless to say, Jeff's solution is easier than my second one. I was
> wrestling in dealing with the greedy nature of regex's and so shifted to
> thinking about the use of the functions that I proposed in the second
> scenario.
>
> Also, I was a bit hypo-caffeinated ... ;-)
>
> Regards,
>
> Marc
>
>
> > On Dec 11, 2015, at 9:12 AM, Adrian Dușa <dusa.adr...@unibuc.ro> wrote:
> >
> > Thanks very much, Marc and Jeff.
> > Jeff's solutions seem to be simple one liners. I really need to learn
> these
> > things, too powerful to ignore.
> >
> > Thank you very much,
> > Adrian
> >
> > On Fri, Dec 11, 2015 at 5:05 PM, Jeff Newmiller <
> jdnew...@dcn.davis.ca.us>
> > wrote:
> >
> >> The gsub function is your friend.
> >>
> >> s <- "A1{0}~B0{1} CO{a2}NN{12}"
> >> gsub( "([^{}]*)\\{([^{}]*)\\}", "\\1 ", s )
> >> gsub( "([^{}]*)\\{([^{}]*)\\}", "\\2 ", s )
> >>
> >> but keep in mind that there are many resources on the Internet for
> >> learning about regular expressions... they are hardly R-specific.
> >>
> >> --
> >> Sent from my phone. Please excuse my brevity.
> >>
> >> On December 11, 2015 5:50:28 AM PST, "Adrian Dușa" <
> dusa.adr...@unibuc.ro>
> >> wrote:
> >>>
> >>> For the regexp aficionados, out there:
> >>>
> >>> I need a regular expression to extract either everything within some
> >>> brackets, or everything outside the brackets, in a string.
> >>>
> >>> This would be the test string:
> >>> "A1{0}~B0{1} CO{a2}NN{12}"
> >>>
> >>> Everything outside the brackets would be:
> >>>
> >>> "A1 ~B0 CO NN"
> >>>
> >>> and everything inside the brackets would be:
> >>>
> >>> "0 1 a2 12"
> >>>
> >>> I have a working solution involving strsplit(), but I wonder if there
> is a
> >>> more direct way.
> >>> Thanks in advance for any hint,
> >>> Adrian
> >>>
> >>>
> >
> >
> > --
> > Adrian Dusa
> > University of Bucharest
> > Romanian Social Data Archive
> > Soseaua Panduri nr.90
> > 050663 Bucharest sector 5
> > Romania
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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.
>
>


-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] fill the area outside a polygon

2015-12-03 Thread Adrian Dușa
On Wed, Dec 2, 2015 at 10:38 PM, Michael Sumner <mdsum...@gmail.com> wrote:

>
> On Wed, 2 Dec 2015 at 23:10 Adrian Dușa <dusa.adr...@unibuc.ro> wrote:
>
>> Dear All,
>>
>> I know how to fill a polygon, using a basic R graphics device:
>>
>> par(mai=c(0, 0, 0, 0))
>> plot(1:100, type="n")
>> polygon(c(20, 80, 80, 20), c(20, 20, 80, 80), col="lightblue")
>>
>>
>> But let's say I have an outer polygon like this:
>> polygon(c(0,100,100,0), c(0,0,100,100))
>>
>> Is it possible to fill the area between the two polygons?
>>
>>
> Try polypath with the evenodd rule (vs. the winding rule):
>

Oh, that is sweet!
I didn't even know about the polypath() function. Time to study now...

Thanks a lot!
Adrian

-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] fill the area outside a polygon

2015-12-03 Thread Adrian Dușa
Hi Greg,

On Wed, Dec 2, 2015 at 10:28 PM, Greg Snow <538...@gmail.com> wrote:
>
> Adrian,
>
> Draw the polygon once without the border and the whole in it, then go
> back and draw the border around the outer polygon without any fill.

I thought about it too, but this only works on a Windows machine.
On a MacOS, the polygon() function doesn't help very much, apparently.

Best wishes,
Adrian

--
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] fill the area outside a polygon

2015-12-02 Thread Adrian Dușa
On Wed, Dec 2, 2015 at 5:19 PM, David L Carlson  wrote:
>
> Using only base graphics, one solution would be to embed the inner
polygon in the outer one and turn off the border:
>
> par(mai=c(0, 0, 0, 0))
> plot(1:100, type="n")
> polygon(c(0, 100, 100, 0, 0, 20, 80, 80, 20, 20, 0),
>  c(0, 0, 100, 100, 0, 20, 20, 80, 80, 20, 0), col="lightblue",
border=NA)


I see what you did, interesting.
I do need the border though, although if this is the only solution, perhaps
I could live without it.

It's working on a Windows machine (which I presume you are using), but
under MacOS I only get  the entire big polygon filled, including the hole
in the middle.

Thanks,
Adrian

--
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] fill the area outside a polygon

2015-12-02 Thread Adrian Dușa
Dear All,

I know how to fill a polygon, using a basic R graphics device:

par(mai=c(0, 0, 0, 0))
plot(1:100, type="n")
polygon(c(20, 80, 80, 20), c(20, 20, 80, 80), col="lightblue")


But let's say I have an outer polygon like this:
polygon(c(0,100,100,0), c(0,0,100,100))

Is it possible to fill the area between the two polygons?

I realise there is a quick and dirty solution to fill the outer polygon,
then draw the inner polygon colored with white, but I would like to
actually "clip" the outer polygon to the boundaries of the inner one.

Of course, there are various packages which draw maps (i.e. maptools), but
I need this in base R graphics. In other words, is it possible to define a
polygon with a hole inside, in base R?

Thank you,
Adrian

-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] detect computer drives

2015-11-27 Thread Adrian Dușa
On Fri, Nov 27, 2015 at 4:03 PM, Dirk Eddelbuettel  wrote:

>
> On 27 November 2015 at 15:43, Adrian Duşa wrote:
> | Is there a method to detect the computer's drives?
> | That would include USB sticks, when they are recognised by the operating
> | system.
>
> That is very obviously OS-dependent amd would need to be wrapped
> conditional
> on the OS.  In R you can test for _explicitly named_ directories and files,
> but not more.


OK, thanks very much, it helps.
Adrian

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] detect computer drives

2015-11-27 Thread Adrian Dușa
Dear All,

Is there a method to detect the computer's drives?
That would include USB sticks, when they are recognised by the operating
system.

I believe to have read somewhere it's possible, but I am unable to find
that message.

Thank you for any hint,
Adrian


-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] open connection to system

2015-07-14 Thread Adrian Dușa
Dear list,

Probably not the best subject line, but hopefully I can explain.
I would like to use R and open a connection to a (system) command line base
chess engine
(for example, there is an open source one at stockfishchess.org)

In the Terminal window (using MacOS), I can type two commands:

$ ./stockfish-6-64 -- this is the first command
Stockfish 6 64 by Tord Romstad, Marco Costalba and Joona Kiiski
go movetime 3000 -- this is the second command

(then lots of lines calculated by the engine, with a final answer after 3
seconds)

First command opens a connection to the chess engine, the seconds one tells
it to search for a move.
The question is, can I do this via R?

I tried the system() command, which works with the first command:
 system(./stockfish-6-64, intern=TRUE)
[1] Stockfish 6 64 by Tord Romstad, Marco Costalba and Joona Kiiski

but it closes the connection and returns an error if I attempt the second
command:

 system(./stockfish-6-64\ngo movetime 3000, intern=TRUE)
Error in system(./stockfish-6-64\ngo movetime 3000, intern = TRUE) :
  error in running command
sh: line 1: go: command not found


Any hint would be really appreciated, thanks in advance,
Adrian

-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] regex find anything which is not a number

2015-03-12 Thread Adrian Dușa
On Thu, Mar 12, 2015 at 9:52 PM, John McKown
john.archie.mck...@gmail.com wrote:
 [...]
 One problem is that Adrian wanted, for some reason, to exclude numbers
 such as 2. but accept 2.0 . That is, no unnecessary trailing
 decimal point. as.numeric() will not fail on 2. since that is a
 number. The example grep() specifically excludes this by requiring at
 least one digit after any decimal point.

Indeed, but that was completely unintentional since I knew .2 should
be a number and I somehow thought 2. was not supposed to be a
number.
I learned a lot about regular expressions (thanks again John), and
both solutions work (thanks very much Steve as well).

Best,
Adrian

-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] regex find anything which is not a number

2015-03-11 Thread Adrian Dușa
Perfect, perfect, perfect.
Thanks very much, John.
Adrian

On Wed, Mar 11, 2015 at 10:00 PM, John McKown
john.archie.mck...@gmail.com wrote:
 See if the following will work for you:

 grep('^-?[0-9]+([.]?[0-9]+)?$',myvector,perl=TRUE,invert=TRUE)

 myvector - c(a3, N.A, 1.2, -3, 3-2, 2.)
 grep('^-?[0-9]+([.][0-9]+)?$',myvector,perl=TRUE,invert=TRUE)
 [1] 1 2 5 6


 The key is to match a number, and then invert the TRUE / FALSE (invert=TRUE).
 ^ == start of string
 -? == 0 or 1 minus signs
 [0-9]+ == one or more digits

 optionally followed by the following via use of (...)?
 [.] == an actual period. I tried to escape this, but it failed
 [0-9]+ == followed by one or more digits

 $ == followed by the end of the string.

 so: optional minus, followed by one or more digits, optionally
 followed by (a period with one or more ending digits).


 On Wed, Mar 11, 2015 at 2:27 PM, Adrian Dușa dusa.adr...@unibuc.ro wrote:
 Hi everyone,

 I need a regular expression to find those positions in a character
 vector which contain something which is not a number (either positive
 or negative, having decimals or not).

 myvector - c(a3, N.A, 1.2, -3, 3-2, 2.)

 In this vector, only positions 3 and 4 are numbers, the rest should be 
 captured.
 So far I am able to detect anything which is not a number, excluding - and .

 grep([^-0-9.], myvector)
 [1] 1 2

 I still need to capture positions 5 and 6, which in human language
 would mean to detect anything which contains a - or a . anywhere
 else except at the beginning of a number.

 Thanks very much in advance,
 Adrian


 --
 Adrian Dusa
 University of Bucharest
 Romanian Social Data Archive
 Soseaua Panduri nr.90
 050663 Bucharest sector 5
 Romania

 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 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.



 --
 He's about as useful as a wax frying pan.

 10 to the 12th power microphones = 1 Megaphone

 Maranatha! 
 John McKown



-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] regex find anything which is not a number

2015-03-11 Thread Adrian Dușa
Hi everyone,

I need a regular expression to find those positions in a character
vector which contain something which is not a number (either positive
or negative, having decimals or not).

myvector - c(a3, N.A, 1.2, -3, 3-2, 2.)

In this vector, only positions 3 and 4 are numbers, the rest should be captured.
So far I am able to detect anything which is not a number, excluding - and .

 grep([^-0-9.], myvector)
[1] 1 2

I still need to capture positions 5 and 6, which in human language
would mean to detect anything which contains a - or a . anywhere
else except at the beginning of a number.

Thanks very much in advance,
Adrian


-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] detect escape character

2014-06-05 Thread Adrian Dușa
On Tue, Jun 3, 2014 at 8:44 PM, David Winsemius dwinsem...@comcast.net wrote:

 On Jun 3, 2014, at 11:03 AM, Adrian Dușa wrote:

 Dear All,

 I should be knowing this, but not get it right...

 I'm a little surprised to see you ask this, too, but we each have lacunae in 
 our R knowledge, so I hope this helps:

Thanks very much David, yes indeed sometimes even the most basic
things can slip out... but I am grateful for this r-help list.
Apologies for the late reply, I am attending a conference all the way
in Toronto and the difference in time plus the activity here makes it
a bit more difficult to catch up.

Best wishes,
Adrian


-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
+40 21 3120210 / int.101
Fax: +40 21 3158391

__
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] detect escape character

2014-06-03 Thread Adrian Dușa
Dear All,

I should be knowing this, but not get it right... For a string like this:

Man\Woman

I would like to detect the escape character \ and replace it with /.

Tried various ways using gsub(), but don't get it right yet. Any suggestion
would be highly welcomed...

Thank you,
Adrian

-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
+40 21 3120210 / int.101
Fax: +40 21 3158391

[[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] Save P values calculated with anova

2013-11-04 Thread Adrian Dușa
That would be:
MyAnova$Pr(F)

and since that is an Anova table, you actually only need the first value:
MyAnova$Pr(F)[1]

Hope this helps,
Adrian


On Mon, Nov 4, 2013 at 4:10 PM, Anders Tisell anders.tis...@liu.se wrote:

 Hi,

 I have created a mixed linear model with one fixed factor and two
 random factors then I would like to test if there is a significant
 difference between the two groups.

 To do this I calculate the model with the lmer function:

  MyModel - lmer(...)

 and do a anova of the model to estimate if the F value is significant.

  MyAnova - anova(MyModel)

 And I get a summary table of the anova with F values, Pr(F) when i
 try to extract this values using the $ function:

  MyAnova$Pr(F)

 I get the error message:

 Error: unexpected symbol '' in MyAnova$Pr(

 I also get this message if I try to extract F value, Mean Sq etc But
 not for DF, Denom etc, so I guess it is the white space and 
 characters that is the problem. What should I do to get the P values
 so I can write them in to a file?

 I am using R 3.0.2 GUI 1.62 Snow Lepard build (6558) on a Mac Mini OS X 10.9

 Best regards
 /Anders


 Sent from Anders iPad

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




-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
+40 21 3120210 / int.101
Fax: +40 21 3158391

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