Re: [R] Help

2024-02-04 Thread Martin Møller Skarbiniks Pedersen
On Sun, 4 Feb 2024 at 17:26, Jibrin Alhassan  wrote:
>
> Here is the script I used to plot the graph indicating the text I wanted to
> insert. The line in the script that I have issues with is: text(-8,-8,
> "R^2=  0.62",  r = 0.79, N = 161", cex = 2
> R^2=  0.62 is not producing R squared = 0.62.
> Thanks.

This works for me:

curve(dnorm, from=-3, to=3, main="Normal Distribution")
text(x=0, y=0.1, cex=1.5, expression(R^2 == 0.62))

if you are used to write expression using LaTeX math , then maybe you
like the latex2exp package:
curve(dnorm, from=-3, to=3, main="Normal Distribution")
text(0, 0.1, latex2exp::TeX("$R^2 = 0.62$"))

Regards
Martin

__
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] List of Words in BioWordVec

2024-02-03 Thread Martin Møller Skarbiniks Pedersen
On Fri, Feb 2, 2024, 01:37 TJUN KIAT TEO  wrote:

> Is there a way to extract list of words in  BioWordVec  in R
>

library(text)


word_vectors <- textEmbed(texts = NULL, model = 'bioWordVecModel',
model_type = 'wordvectors')

word_list <- rownames(word_vectors$wordvectors)

[[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] Suggestion for list - change reply-to

2023-12-14 Thread Martin Møller Skarbiniks Pedersen
Hi,

  I suggest that reply-to is changed to r-help@r-project.org and not
the original sender.

  The reason for my suggestion:
  I just made a mistake when replying to a message.
  I forgot to change the reply address from the sender to the r-help
and I think that happens quite often for others also.

  Any reason to keep it to the original sender?

Regards
Martin

__
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 based a custom sorting function

2023-12-14 Thread Martin Møller Skarbiniks Pedersen
On Thu, 14 Dec 2023 at 12:02, Duncan Murdoch  wrote:
>

> class(df$value) <- "sizeclass"
>
> `>.sizeclass` <- function(left, right) custom_sort(unclass(left),
> unclass(right)) == 1
>
> `==.sizeclass` <- function(left, right) custom_sort(unclass(left),
> unclass(right)) == 0
>
> `[.sizeclass` <- function(x, i) structure(unclass(x)[i], class="sizeclass")
>
> df[order(df$value),]
>
> All the "unclass()" calls are needed to avoid infinite recursion.  For a
> more complex kind of object where you are extracting attributes to
> compare, you probably wouldn't need so many of those.

Great! Just what I need. I will create a class and overwrite > and ==.
I didn't know that order() used these exact methods.

My best solution was something like this:

quicksort <- function(arr, compare_func) {
  if (length(arr) <= 1) {
return(arr)
  } else {
pivot <- arr[[1]]
less <- arr[-1][compare_func(arr[-1], pivot) <= 0]
greater <- arr[-1][compare_func(arr[-1], pivot) > 0]
return(c(quicksort(less, compare_func), pivot, quicksort(greater,
compare_func)))
  }
}

persons <- c("alfa", "bravo", "charlie", "delta", "echo", "foxtrot", "golf",
 "hotel", "india", "juliett", "kilo", "lima", "mike", "november",
 "oscar", "papa", "quebec", "romeo", "sierra", "tango", "uniform",
 "victor", "whiskey", "x-ray", "yankee", "zulu")

quicksort(persons, function(left, right) {
  nchar(left) - nchar(right)
})

Regards
Martin

__
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 based a custom sorting function

2023-12-14 Thread Martin Møller Skarbiniks Pedersen
> This sounds suspiciously like homework (which is off-topic... see the Posting 
> Guide)

It is not homework.
Currently I am trying to solve this: https://adventofcode.com/2023/day/7

But it is something that has puzzled me for a long time.
In many programming languages, you can give a "less" function to the
sorting function.

The "less" function normally takes two arguments and tells which is
greater. The sorting function then uses that.
Eg. in perl:
@products = sort { $a->{price} <=> $b->{price} || $b->{discount} <=>
$a->{discount} } @products;

>  and you haven't indicated how you plan to encode your poker hands
> If this is not homework, then please show your work so far instead of showing 
> a completely different example.

I believe a MRE is better than a lot of code with many details that
are not related to the precise problem.
See https://stackoverflow.com/help/minimal-reproducible-example

My encoding of poker hands doesn't matter for the general problem of
providing a custom sorting function to any of the many
sorting functions in R.

> Most core features of other languages are possible in R so if you really 
> understand these other techniques and R then you should be able to do this 
> already.

I understand R quite well and implemented my own quicksort but I was
wondering for a better solution.

Here is my current solution.

quicksort <- function(arr, compare_func) {
  if (length(arr) <= 1) {
return(arr)
  } else {
pivot <- arr[1]
less <- arr[-1][compare_func(arr[-1], pivot) <= 0]
greater <- arr[-1][compare_func(arr[-1], pivot) > 0]
return(c(quicksort(less, compare_func), pivot, quicksort(greater,
compare_func)))
  }
}

Regards
Martin



Martin

__
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] Sorting based a custom sorting function

2023-12-14 Thread Martin Møller Skarbiniks Pedersen
Hi,

  I need to sort a data.frame based on a custom sorting function.
  It is easy in many languages but I can't find a way to do it in R.

  In many cases I could just use an ordered factor but my data.frame
contains poker hands and
I need to rank these hands. I already got a function that compares two hands.

Here is a MRE (Minimal, Reproducible Example):


df <- data.frame(person = c("Alice", "Bob", "Charlie"), value =
c("Medium", "Small", "Large"))

# 0 means equal, -1 means left before right, 1 means right before left
custom_sort <- function(left, right) {
  if (left == right) return(0)
  if (left == "Small") return(-1)
  if (left == "Medium" & right == "Large") return(-1)
  return(1)
}

#  sort df according to custom_soft
# expect output is a data.frame:
# name   size
# 1 Bob Medium
# 2   Alice  Small
# 3 Charlie  Large

In this simple case I can just use an ordered factor but what about
the poker hands situation?

Regards
Martin

__
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] Confirming MySQL Alive

2023-10-08 Thread Martin Møller Skarbiniks Pedersen
You don't need sudo to run:
systemctl status

On Sat, Oct 7, 2023, 17:09 Stephen H. Dawson, DSL via R-help <
r-help@r-project.org> wrote:

> Hi,
>
>
> Getting some data from an older MySQL box. I had an event recently where
> the MySQL box went off-line for maintenance without a prior announcement
> of service disruption.
>
> I decided to add a line on my local version of MySQL as I considered how
> to handle this condition going forward.
>
> system("sudo systemctl status mysql", input =
> rstudioapi::askForPassword("sudo password"))
>
> system("sudo systemctl status mysql",input=readline("Enter Password: "))
>
>
> Both fail for the same reason, saying I need a terminal.
>
>
>  > system("sudo systemctl status mysql", input =
> rstudioapi::askForPassword("sudo password"))
> sudo: a terminal is required to read the password; either use the -S
> option to read from standard input or configure an askpass helper
> sudo: a password is required
>  >
>
>
>
>  > system("sudo systemctl status mysql",input=readline("Enter Password: "))
> Enter Password: ***REDACTED***
> sudo: a terminal is required to read the password; either use the -S
> option to read from standard input or configure an askpass helper
> sudo: a password is required
>  >
>
>
>
> I can run the code segments for things like ls and pwd. So, there is
> something unique about systemctl and R that is beyond my understanding
> today.
>
> QUESTIONS
> What is so special about systemctl and R in a system syntax statement?
>
> What are some of the best practices to confirm a box I am hitting for
> data with R , either local or across the network, has MySQL up and running?
>
>
> Thanks,
> --
> *Stephen Dawson, DSL*
> /Executive Strategy Consultant/
> Business & Technology
> +1 (865) 804-3454
> http://www.shdawson.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.
>

[[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 with plotting and date-times for climate data

2023-09-15 Thread Martin Møller Skarbiniks Pedersen
Change

 geom_point(aes(y = tmax_mean, color = "blue"))
to
 geom_point(aes(y = tmax_mean), color = "blue")
if you want blue points.

aes(color = ) does not set the color of the points.

aes(color = ) takes a column (best if it is a factor) and uses that for
different colors.


/Martin

On Tue, Sep 12, 2023, 22:50 Kevin Zembower via R-help 
wrote:

> Hello,
>
> I'm trying to calculate the mean temperature max from a file of climate
> date, and plot it over a range of days in the year. I've downloaded the
> data, and cleaned it up the way I think it should be. However, when I
> plot it, the geom_smooth line doesn't show up. I think that's because
> my x axis is characters or factors. Here's what I have so far:
> 
> library(tidyverse)
>
> data <- read_csv("Ely_MN_Weather.csv")
>
> start_day = yday(as_date("2023-09-22"))
> end_day = yday(as_date("2023-10-15"))
>
> d <- as_tibble(data) %>%
> select(DATE,TMAX,TMIN) %>%
> mutate(DATE = as_date(DATE),
>yday = yday(DATE),
>md = sprintf("%02d-%02d", month(DATE), mday(DATE))
>) %>%
> filter(yday >= start_day & yday <= end_day) %>%
> mutate(md = as.factor(md))
>
> d_sum <- d %>%
> group_by(md) %>%
> summarize(tmax_mean = mean(TMAX, na.rm=TRUE))
>
> ## Here's the filtered data:
> dput(d_sum)
>
> > structure(list(md = structure(1:25, levels = c("09-21", "09-22",
> "09-23", "09-24", "09-25", "09-26", "09-27", "09-28", "09-29",
> "09-30", "10-01", "10-02", "10-03", "10-04", "10-05", "10-06",
> "10-07", "10-08", "10-09", "10-10", "10-11", "10-12", "10-13",
> "10-14", "10-15"), class = "factor"), tmax_mean = c(65,
> 62.2,
> 61.3, 63.9, 64.3, 60.1, 62.3, 60.5, 61.9,
> 61.2, 63.7, 59.5, 59.6, 61.6,
> 59.4, 58.8, 55.9, 58.125,
> 58, 55.7, 57, 55.4, 49.8,
> 48.75, 43.7)), class = c("tbl_df", "tbl", "data.frame"
> ), row.names = c(NA, -25L))
> >
> ggplot(data = d_sum, aes(x = md)) +
> geom_point(aes(y = tmax_mean, color = "blue")) +
> geom_smooth(aes(y = tmax_mean, color = "blue"))
> =
> My questions are:
> 1. Why isn't my geom_smooth plotting? How can I fix it?
> 2. I don't think I'm handling the month and day combination correctly.
> Is there a way to encode month and day (but not year) as a date?
> 3. (Minor point) Why does my graph of tmax_mean come out red when I
> specify "blue"?
>
> Thanks for any advice or guidance you can offer. I really appreciate
> the expertise of this group.
>
> -Kevin
>
> __
> 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] Book Recommendation

2023-08-28 Thread Martin Møller Skarbiniks Pedersen
The SQLite is a good database to use.

https://cran.r-project.org/web/packages/RSQLite/vignettes/RSQLite.html

On Mon, Aug 28, 2023, 22:12 Stephen H. Dawson, DSL via R-help <
r-help@r-project.org> wrote:

>
> This is an academic course. The effort now is to nail down the former. I
> am pushing against a local db for the students. I prefer they focus on
> the get-and-analyze efforts and not db administration efforts.
>
>

[[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] Fwd: alternative way to define a function

2021-12-02 Thread Martin Møller Skarbiniks Pedersen
On Thu, 2 Dec 2021 at 12:40, Ivan Krylov  wrote:
>
>
> The \(arguments) syntax has been introduced in R 4.1.0:
> https://cran.r-project.org/doc/manuals/r-release/NEWS.html (search for
> "\(x)"). It is the same as function(arguments).
>
> The only benefit is slightly less typing; could be useful if you use
> the native R pipe (also introduced in R 4.1.0, search for "|>") and
> want to call an anonymous function in the right-hand side of the pipe.

Thanks. It is a nice new feature.
I will start using it in my apply fun's eg: apply(mtcars, 2, \(x)
length(unique(x)))

Regards
Martin

[[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] Fwd: alternative way to define a function

2021-12-02 Thread Martin Møller Skarbiniks Pedersen
By reading some code today I have just discovered an alternative way to
define a function:
f <- \(x, y) x * y

Is that exactly the same as:
f <- function(x,y) x * y
?

Is there any benefit to the first or second way to define a function?

Regards
Martin

[[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] Is there a hash data structure for R

2021-11-02 Thread Martin Møller Skarbiniks Pedersen
On Tue, 2 Nov 2021 at 10:48, Yonghua Peng  wrote:
>
> I know this is a newbie question. But how do I implement the hash
structure
> which is available in other languages (in python it's dict)?
>

As other posters wrote then environments are the solution.
data.frames, vectors and lists are much slower and less useful to use as
key-value pairs.

Here are some code I somethings uses:

cache <- NULL

cache_set <- function(key, value) {
  assign(key, value, envir = cache)
}

cache_reset <- function() {
  cache <<- new.env(TRUE, emptyenv())
}

cache_get <- function(key) {
  get(key, envir = cache, inherits = FALSE)
}

cache_has_key <- function(key) {
  exists(key, envir = cache, inherits = FALSE)
}
cache_reset()

[[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] docker containers and R

2021-10-27 Thread Martin Møller Skarbiniks Pedersen
On Wed, 27 Oct 2021 at 20:53, Bogdan Tanasa  wrote:

> Dear all, would you please advise :
>
> shall I have a container that runs R (below), and install specifically a
> package called UMI4Cats, obviously, a lot of other libraries are
> installed.How can I save the docker container that contains the additional
> libraries that I have installed and are required by UMI4Cats ?
>

You use "docker commit" - see
https://docs.docker.com/engine/reference/commandline/commit/

But consider making a Dockerfile instead.

Regards
Martin

[[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] Still puzzled about different graph

2021-04-24 Thread Martin Møller Skarbiniks Pedersen
>
> I don't know where it says this in the docs, but generally speaking
> ggplot2 graphs don't evaluate everything until you print them.  So I'd
> expect p3's two geom_path components to be identical, even though you
> changed idx.
>
> I think you can force evaluation before printing (using ggplot_build),
> but I don't think you can modify the graph after that, so you'll need
> two different variables instead of changing idx.
>
> Duncan Murdoch


Thanks. Now I understand the problem and can find a solution.

Regards
Martin

[[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] ggplot2::geom_path() in a loop problems.

2021-04-24 Thread Martin Møller Skarbiniks Pedersen
On Fri, 23 Apr 2021 at 20:51, Chris Evans  wrote:
>
> I may be quite wrong but isn't the for loop in the second example simply
overwriting/replacing the first p2 with the second whereas the p1 version
is adding the paths to p1.
>
> (If you see what I mean, I don't think I have expressed that very well.)
>
> Very best (all),
>
> Chris


Hi Chris,
  Thanks for your email. However I don't think that is the problem.
  Same problem here:

library(ggplot2)

df <- data.frame(x = c(0,25,0,-25,0), y = c(25,0,-25,0,25))
p1 <- ggplot()
p1 <- p1 + geom_path(data = df,aes(x = x/1, y = y/1))
p1 <- p1 + geom_path(data = df,aes(x = x/2, y = y/2))
p1 <- p1 + xlim(-30,30)
p1 <- p1 + ylim(-30,30)
p1

df <- data.frame(x = c(0,25,0,-25,0), y = c(25,0,-25,0,25))
p3 <- ggplot()
idx <- 1
p3 <- p3 + geom_path(data = df,aes(x = x/idx, y = y/idx))
idx <- 2
p3 <- p3 + geom_path(data = df,aes(x = x/idx, y = y/idx))
p3 <- p3 + xlim(-30,30)
p3 <- p3 + ylim(-30,30)
p3

[[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] Still puzzled about different graph

2021-04-24 Thread Martin Møller Skarbiniks Pedersen
Hi,

  Any ideas why I don't get the same graph out of p1 and p3?

 I have also posted it in the rstudio community without luck.
https://community.rstudio.com/t/ggplot2-geom-path-in-a-loop/102716/2

library(ggplot2)

df <- data.frame(x = c(0,25,0,-25,0), y = c(25,0,-25,0,25))
p1 <- ggplot()
p1 <- p1 + geom_path(data = df,aes(x = x/1, y = y/1))
p1 <- p1 + geom_path(data = df,aes(x = x/2, y = y/2))
p1 <- p1 + xlim(-30,30)
p1 <- p1 + ylim(-30,30)
p1

df <- data.frame(x = c(0,25,0,-25,0), y = c(25,0,-25,0,25))
p3 <- ggplot()
idx <- 1
p3 <- p3 + geom_path(data = df,aes(x = x/idx, y = y/idx))
idx <- 2
p3 <- p3 + geom_path(data = df,aes(x = x/idx, y = y/idx))
p3 <- p3 + xlim(-30,30)
p3 <- p3 + ylim(-30,30)
p3

[[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] ggplot2::geom_path() in a loop problems.

2021-04-23 Thread Martin Møller Skarbiniks Pedersen
On Fri, 23 Apr 2021 at 20:11, Martin Møller Skarbiniks Pedersen <
traxpla...@gmail.com> wrote:
>
> Hi,
>
> I have some problems understanding how to use geom_path() inside a loop.
> I know the code below is a bit silly but it is just a MRE
> ( https://stackoverflow.com/help/minimal-reproducible-example )
>
> p1 looks like I expect however p2 only contains the last square. I
> expected p2 to be the same as p1.
>
> Any hints what is going on?
> Regards
> Martin
>
> library(ggplot2)
>
> df <- data.frame(x = c(0,25,0,-25,0), y = c(25,0,-25,0,25))
>
> p1 <- ggplot()
> p1 <- p1 + geom_path(data = df,aes(x = x/1, y = y/1))
> p1 <- p1 + geom_path(data = df,aes(x = x/2, y = y/2))
> p1 <- p1 + xlim(-30,30)
> p1 <- p1 + ylim(-30,30)
> p1
>
>
> p2 <- ggplot()
> for (idx in 1:2) {
>   p2 <- p2 + geom_path(data = df,aes(x = x/idx, y = y/idx))
> }
> p2 <- p2 + xlim(-30,30)
> p2 <- p2 + ylim(-30,30)
> p2


And the same strange effect if I write it like this:


p3 <- ggplot()
idx <- 1
p3 <- p3 + geom_path(data = df,aes(x = x/idx, y = y/idx))
idx <- 2
p3 <- p3 + geom_path(data = df,aes(x = x/idx, y = y/idx))
p3 <- p3 + xlim(-30,30)
p3 <- p3 + ylim(-30,30)
p3

[[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] ggplot2::geom_path() in a loop problems.

2021-04-23 Thread Martin Møller Skarbiniks Pedersen
Hi,

I have some problems understanding how to use geom_path() inside a loop.
I know the code below is a bit silly but it is just a MRE
( https://stackoverflow.com/help/minimal-reproducible-example )

p1 looks like I expect however p2 only contains the last square. I
expected p2 to be the same as p1.

Any hints what is going on?
Regards
Martin

library(ggplot2)

df <- data.frame(x = c(0,25,0,-25,0), y = c(25,0,-25,0,25))

p1 <- ggplot()
p1 <- p1 + geom_path(data = df,aes(x = x/1, y = y/1))
p1 <- p1 + geom_path(data = df,aes(x = x/2, y = y/2))
p1 <- p1 + xlim(-30,30)
p1 <- p1 + ylim(-30,30)
p1


p2 <- ggplot()
for (idx in 1:2) {
  p2 <- p2 + geom_path(data = df,aes(x = x/idx, y = y/idx))
}
p2 <- p2 + xlim(-30,30)
p2 <- p2 + ylim(-30,30)
p2

[[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] updating OpenMx failed

2021-04-12 Thread Martin Møller Skarbiniks Pedersen
btw. I installed without problems OpenMx on a xubuntu 20.10 running R 4.0.5.

Are your gcc toolchain up to date?


On Mon, Apr 12, 2021, 00:31 Rich Shepard  wrote:

> On Sun, 11 Apr 2021, Martin Møller Skarbiniks Pedersen wrote:
>
> > You should contact the maintainers of the package.
> > According to this page:
> > https://cran.r-project.org/web/packages/OpenMx/index.html
> > you can get help from http://openmx.ssri.psu.edu/forums
>
> Martin,
>
> You're correct. I should have looked up the maintainer and directly
> contacted them. I'll do so.
>
> Regards,
>
> Rich

[[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] updating OpenMx failed

2021-04-11 Thread Martin Møller Skarbiniks Pedersen
On Sun, 11 Apr 2021 at 18:10, Rich Shepard  wrote:
>
> I'm running Slackware-14.2/x86_64 and R-4.0.2-x86_64-1_SBo.
>
> Updating OpenMx failed:
> omxState.cpp:1230:82:   required from here
> omxState.cpp:1229:17: error: cannot call member function ‘void
ConstraintVec::eval(FitContext*, double*, double*)’ without object
>   eval(fc2, result.data(), 0);
>   ^

[...]

> Please advise,

You should contact the maintainers of the package.
According to this page:
https://cran.r-project.org/web/packages/OpenMx/index.html
you can get help from http://openmx.ssri.psu.edu/forums

Regards
Martin

[[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] "global parameter" warning using data.table in package.

2021-03-05 Thread Martin Møller Skarbiniks Pedersen
Please ignore my previous email. I just found the R-package-devel mailing
list.

On Fri, 5 Mar 2021 at 14:25, Martin Møller Skarbiniks Pedersen <
traxpla...@gmail.com> wrote:

> Hi,
>
>   I am converting a couple of functions into a R-package. Many of the
> functions use data.table.
>   I have two questions using data.table in my own package.
>   Normally I would put each question in separate emails but I think they
> might be connected.
>
> First question is short and I think the answer is yes.
> 1. Do I always need to prefix data.table each time I use something from
> that package?
> Eg. DT <- data.table::data.table(x=rep(c("b","a","c"),each=3), y=c(1,3,6),
> v=1:9)
>
> Second question is longer.
> 2.  In this small example code:
> hello <- function() {
>   DT <- data.table::data.table(x=rep(c("b","a","c"),each=3), y=c(1,3,6),
> v=1:9)
>   DT[, .(sum(v))]
> }
>
> I get these warnings from R CMD check:
> hello: no visible global function definition for ‘.’
> hello: no visible binding for global variable ‘v’
> Undefined global functions or variables:
>   . v
>
> According to: vignette("datatable-importing", package = "data.table")
> The solution is
> hello <- function() {
>   v <- NULL
>   . <- NULL
>
> And it works but looks a bit weird.
> Is there a better solution?
>
> Regards
> Martin
>


-- 
Til uvedkommende, der læser med: Der er ingen grund til at læse min
mail. Jeg har intet at gøre med FARC, al-Jihad, al-Qaida, Hamas, Hizb
al-Mujahidin eller ETA. Jeg har aldrig gjort Zakat, går ikke ind for
Istishad, har ikke lavet en bilbombe eller kernevåben og jeg ved
dårligt nok, hvad Al Manar og бомба betyder.  Men tak for den udviste
interesse.

Leve Ligemageriet!
Styrk pøbelvældet!
Bevar misundelsesafgifterne og cafepengene!
Hurra for ældrebyrden!

[[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] "global parameter" warning using data.table in package.

2021-03-05 Thread Martin Møller Skarbiniks Pedersen
Hi,

  I am converting a couple of functions into a R-package. Many of the
functions use data.table.
  I have two questions using data.table in my own package.
  Normally I would put each question in separate emails but I think they
might be connected.

First question is short and I think the answer is yes.
1. Do I always need to prefix data.table each time I use something from
that package?
Eg. DT <- data.table::data.table(x=rep(c("b","a","c"),each=3), y=c(1,3,6),
v=1:9)

Second question is longer.
2.  In this small example code:
hello <- function() {
  DT <- data.table::data.table(x=rep(c("b","a","c"),each=3), y=c(1,3,6),
v=1:9)
  DT[, .(sum(v))]
}

I get these warnings from R CMD check:
hello: no visible global function definition for ‘.’
hello: no visible binding for global variable ‘v’
Undefined global functions or variables:
  . v

According to: vignette("datatable-importing", package = "data.table")
The solution is
hello <- function() {
  v <- NULL
  . <- NULL

And it works but looks a bit weird.
Is there a better solution?

Regards
Martin

[[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] How to calculate area and volume of an image with R

2021-02-28 Thread Martin Møller Skarbiniks Pedersen
On Sun, Feb 28, 2021, 17:49 Paul Bernal  wrote:

> Hello everyone,
>
> Is there a way to calculate volume and area of an image with R?


How can an image have a volume or an area?
I think you need to be more specific.

Regards
Martin

[[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] union of two sets are smaller than one set?

2021-01-31 Thread Martin Møller Skarbiniks Pedersen
This is really puzzling me and when I try to make a small example
everything works like expected.

The problem:

I got these two large vectors of strings.

> str(s1)
 chr [1:766608] "0.dk" ...
> str(s2)
 chr [1:59387] "043.dk" "0606.dk" "0618.dk" "0888.dk" "0iq.dk" "0it.dk" ...

And I need to create the union-set of s1 and s2.
I expect the size of the union-set to be between 766608 and 766608+59387.
However it is 681193 which is less that number of elements in s1!

> length(base::union(s1, s2))
[1] 681193

Any hints?

Regards
Martin

[[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] Converting "day of year" to "year", "month" and "day"

2021-01-15 Thread Martin Møller Skarbiniks Pedersen
On Fri, 15 Jan 2021 at 18:55, Jibrin Alhassan 
wrote:
>
> Dear R users,
> I am very new to R software. I have solar wind speed data needed for my
> work. How do I convert day in the year to year, month, and day with R
> software? I have used this code
> as.Date(0, origin = "1998-01-01")

Look at the package lubridate.
Here is an example for you:

library(lubridate)

v <- seq(ymd("2020-01-01"),ymd("2022-01-01"),1)
df <- data.frame(date = v, day = day(v), month = month(v),year = year(v))
str(df)
head(df,3)
tail(df,3)

'data.frame': 732 obs. of  4 variables:
 $ date : Date, format: "2020-01-01" "2020-01-02" ...
 $ day  : int  1 2 3 4 5 6 7 8 9 10 ...
 $ month: num  1 1 1 1 1 1 1 1 1 1 ...
 $ year : num  2020 2020 2020 2020 2020 2020 2020 2020 2020 2020 ...
date day month year
1 2020-01-01   1 1 2020
2 2020-01-02   2 1 2020
3 2020-01-03   3 1 2020
  date day month year
730 2021-12-30  3012 2021
731 2021-12-31  3112 2021
732 2022-01-01   1 1 2022

Regards
Martin

[[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] log of small values in R

2021-01-13 Thread Martin Møller Skarbiniks Pedersen
On Mon, 11 Jan 2021 at 08:22, Shaami  wrote:
>
> Dear FriendsI am facing the problem of log values in R. The
> log(1-0.9) is giving -Inf while log(1e-18) gives finite
> answer. Any suggestion to deal with this problem?  Thank you


This vignette has a lot of good information about log of small numbers.

vignette(package = "Rmpfr", "log1mexp-note")
https://cran.r-project.org/web/packages/Rmpfr/vignettes/log1mexp-note.pdf

Regards
Martin M. S. Pedersen

[[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] ggplot2::coord_fixed() margin problem

2020-12-20 Thread Martin Møller Skarbiniks Pedersen
On Sun, 20 Dec 2020 at 17:43, Rui Barradas  wrote:

Thank you for trying to answer my question.

> I am not sure I understand the problem.
> With coord_fixed() both axis have the same length and the plot is a
> square. When resizing the plot window the white areas can be on
> top/bottom if the window height is bigger than its width or to the
> left/right if it's the other way around.

Yes.

> Does this answer the question?

Nope.
I really need the added space as the same color as the plot.background
(yellow2) in the example below.
However the code below generates a small white space. I was expected it to
be the
same as the plot.background color.

library(ggplot2)
g <-
   ggplot() +
   theme(
  plot.background = element_rect(fill = "yellow2"),
  panel.background = element_rect(fill = "yellow2"),
   )
g <- g + coord_fixed()
g

Regards
Martin

[[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 in cluster sampling: 'mixed with negative subscripts'

2020-12-20 Thread Martin Møller Skarbiniks Pedersen
On Sun, 20 Dec 2020 at 06:22, Richard O'Keefe  wrote:

> More accurately, in x[i] where x and i are simple vectors,
> i may be a mix of positive integers and zeros
>   where the zeros contribute nothing to the result
>

Yes, index 0 doesn't get an error or a warning. I think it should.
Eg.

(v <- 1:4)
[1] 1 2 3 4

v[c(0,2,4)] <- c(0,2)
v
[1] 1 0 3 2 # a surprise ?

Regards
Martin

[[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] ggplot2::coord_fixed() margin problem

2020-12-20 Thread Martin Møller Skarbiniks Pedersen
Hi,
  I posted this on the Google Group for ggplot2 but got no response.
https://groups.google.com/g/ggplot2/c/441srnt6RZU

So I hope someone can help me here instead?!

-

If I don't use the coord_fixed() then all the background is yellow as
expected.
But I need to coord_fixed() and then it adds a little white around my plot.
Is it possible to avoid the white and use coord_fixed() ?

Here is a "Minimal, Reproducible Example":

library(ggplot2)
g <-
  ggplot() +
  theme(
 plot.background = element_rect(fill = "yellow2"),
 panel.background = element_rect(fill = "yellow2"),
  )
g <- g + coord_fixed()
g

Regards
Martin M. S. Pedersen

[[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] RGB -> CYMK, with consistent colors

2020-11-30 Thread Martin Møller Skarbiniks Pedersen
On Sun, 29 Nov 2020 at 20:55, Derek M Jones  wrote:
[...]
>
> library("colorspace")
>
> two_c=rainbow(2)
> x=runif(20)
> y=runif(20)
> plot(x, y, col=two_c[2])
> pdf(file="cmyk.pdf", colormodel="cmyk")
> plot(x, y, col=two_c[2])
> dev.off()

rainbow(2) gives two RGB-colours: #FF (=pure red) and #00 (=pure
cyan).
So it should be no problem to match two_c[2] perfect in CMYK-colourspace

However after some testing.
I totally agree that CMYK handling in R using pdf(..., colormodel = "cmyk")
is not correct.

One solution:
Output in tiff or png instead and then convert to CMYK using external tools.

Try this:
png("plot.png")
plot(runif(10), runif(10), col =  ""#00") # cyan
dev.off()

And then convert plot.png using:
https://www.online-utility.org/image/convert/to/CMYK

Regards
Martin

[[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] RGB -> CYMK, with consistent colors

2020-11-29 Thread Martin Møller Skarbiniks Pedersen
On Sun, 29 Nov 2020 at 14:26, Derek Jones  wrote:

[...]

> I can regenerate the images, and explicitly specify cmyk.  But using:
>
> pdf.options(colormodel="cymk")
>
> does not change anything.  The colors look remarkably similar to
> those produced via the ghostview route.

[...]

> Does anybody have any ideas for producing cmyk images that have
> the same (or close enough) look as the RGB?

Have you tried printed a few pages in CMYK?

A monitor is based on mixing light using Red-Green-Blue. So it is not
possible for the monitor to show
CMYK which must be printed on paper to view correctly.

Regards
Martin

[[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] analyzing results from Tuesday's US elections

2020-11-11 Thread Martin Møller Skarbiniks Pedersen
Please watch this video if you wrongly believe that Benford's law easily
can be applied to elections results.

https://youtu.be/etx0k1nLn78



On Sun, Nov 1, 2020, 21:17 Spencer Graves <
spencer.gra...@effectivedefense.org> wrote:

> Hello:
>
>
>What can you tell me about plans to analyze data from this year's
> general election, especially to detect possible fraud?
>
>
>I might be able to help with such an effort.  I have NOT done
> much with election data, but I have developed tools for data analysis,
> including web scraping, and included them in R packages available on the
> Comprehensive R Archive Network (CRAN) and GitHub.[1]
>
>
>Penny Abernathy, who holds the Knight Chair in Journalism and
> Digital Media Economics at UNC-Chapel Hill, told me that the electoral
> fraud that disqualified the official winner from NC-09 to the US House
> in 2018 was detected by a college prof, who accessed the data two weeks
> after the election.[2]
>
>
>Spencer Graves
>
>
> [1]
> https://github.com/sbgraves237
>
>
> [2]
> https://en.wikiversity.org/wiki/Local_Journalism_Sustainability_Act
>
> __
> 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 in R code

2020-10-18 Thread Martin Møller Skarbiniks Pedersen
I think you first should read and understand this:
https://stackoverflow.com/help/minimal-reproducible-example
and
https://stackoverflow.com/help/how-to-ask

On Sun, Oct 18, 2020, 11:57 Faheem Jan via R-help 
wrote:

> Good morning,  Please help me to code this code in R.
> I working in the multivariate time series data, know my objective is that
> to one year forecast of the hourly time series data, using first five as a
> training set and the remaining one year as validation. For this  I
> transform the the data into functional data through Fourier basis
> functional, apply functional principle components as dimensional reduction
> explaining a specific amount of variation   , using the corresponding
> functional principle components scores. I use the VAR model on those
> FPCscores for forecasting one day ahead forecast, know my problem is that i
> choose four Fpc scores which give only four value in a single day, I want
> the forecast for 24 hours not only 4, and then i want to transform it back
> to the original functional data. for the understanding i am sharing my code
> (1) transform of the multivariate time series data in functional data(2)
> the functional principle components and the corresponding scores(3) I use
> functional final prediction error for the selection of the parameters on
> the VAR model(4) Using VAR for the analysis and forecasting .(1) nb = 23 #
> number of basis functions for the data  fbf =
> create.fourier.basis(rangeval=c(0,1), nbasis=nb) # basis for data
> args=seq(0,1,length=24)  fdata1=Data2fd(args,y=t(mat),fbf) # functions
> generated from discretized y(2) ffpe = fFPE(fdata1, Pmax=10)  d.hat =
> ffpe[1] #order of the model  p.hat = ffpe[2] #lag of the model
> (3) n = ncol(fdata1$coef)  D = nrow(fdata1$coef)  #center the data  mu =
> mean.fd(fdata1)  data = center.fd(fdata1)  #fPCA  fpca =
> pca.fd(data,nharm=D)  scores = fpca$scores[,1:d.hat](4) # to avoid warnings
> from vars predict function below  colnames(scores) <-
> as.character(seq(1:d.hat))  VAR.pre= predict(VAR(scores, p.hat),
> n.ahead=1, type="const")$fcst
> after this I need help first how to transform this into original
> Functional data and to obtain the for for each 24 hours (mean one day
> forecast) and to how to generalize the result for one year.
>
>
> [[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.
>

[[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] ggplot to visualize data

2020-06-08 Thread Martin Møller Skarbiniks Pedersen
On Mon, 8 Jun 2020 at 18:25, Neha gupta  wrote:

> I am still waiting for someone to respond.
>
>
Please read this guide about asking questions and try again on the correct
mailing-list.
https://www.r-project.org/posting-guide.html

Regards
Martin

[[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] bug or just me

2020-05-30 Thread Martin Møller Skarbiniks Pedersen
Hi,
  Is this a bug or just me doing something stupid?
  solve(m) never returns and eats 100% CPU.

> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3

Random number generation:
 RNG: Mersenne-Twister
 Normal:  Inversion
 Sample:  Rounding

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

loaded via a namespace (and not attached):
[1] compiler_3.6.3
> set.seed(1)
> m <- matrix(sample(1:25), nrow=5)
> solve(m)

[[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] Package installation problem

2020-05-29 Thread Martin Møller Skarbiniks Pedersen
On Fri, 29 May 2020 at 07:03, John via R-help  wrote:

> I'm not certain just what this problem is.  Trying to install the
> "curl" package, which "tseries" wants results in the following error:
>
> 
> Package libcurl was not found in the pkg-config search path.
> Perhaps you should add the directory containing `libcurl.pc'
>

Just run:
sudo dnf install libcurl-devel

Regards
Martin

[[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] extremely long installation of devtools

2020-03-09 Thread Martin Møller Skarbiniks Pedersen
On Mon, 9 Mar 2020 at 09:57, Christopher C. Lanz via R-help
 wrote:

> Help! I followed the instructions I found to install ggbiplot, and entered 
> "install_packages("devtools")" about 25 minutes ago, and the installation 
> procedure is continuing as I write this.

Hi,

  This is a lot of guess-work because you didn't write which
operationsystem or which version of R you are using.
  Also I guess you wrote: "install.packages("devtools") and not
install_packages("devtools").

  If you are using Windows, then you might the Rtools package before
installing devtools.
  If you are using Linux, then you might need to install a
C/C++-compiler for your Linux first.
  If ...

Please read and understand this: https://stackoverflow.com/help/how-to-ask









Although it's difficult to tell, there appears to be substantial
repetition in the messages displayed.
>
> Should I terminate the process, or is this a normal event?
>
> Thanks! (Please respond to this email [also?] because I can't enter R as the 
> process is continuing. lan...@potsdam.edu)
>
>
> Chris Lanz
>
> Department of Computer Science
>
> 340 Dunn Hall, SUNY Potsdam
>
> lan...@potsdam.edu
>
> 315 267 2407
>
> 315 268 1547
>
>
> "The reason academic conflicts are so bitter is that the stakes are so low."
>
> Sayre's Law (not the original, but a correct wording)
>
> [[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.



-- 
Til uvedkommende, der læser med: Der er ingen grund til at læse min
mail. Jeg har intet at gøre med FARC, al-Jihad, al-Qaida, Hamas, Hizb
al-Mujahidin eller ETA. Jeg har aldrig gjort Zakat, går ikke ind for
Istishad, har ikke lavet en bilbombe eller kernevåben og jeg ved
dårligt nok, hvad Al Manar og бомба betyder.  Men tak for den udviste
interesse.

Leve Ligemageriet!
Styrk pøbelvældet!
Bevar misundelsesafgifterne og cafepengene!
Hurra for ældrebyrden!

__
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] Executing an R script and show the plots.

2020-01-29 Thread Martin Møller Skarbiniks Pedersen
On Sun, 26 Jan 2020 at 16:30, Felix Blind  wrote:
>

> But when I put the same code in a file script.r and run it with R -f
> script.r or if I source it in the REPL with source("script.r") I do not
> get any plots shown.
>
> Can you guys tell me what I do wrong. (Apart from either using RStudio
> or the REPL exclusively)

Add Sys.sleep(Inf) to the end of your script.r and run it with

R --interactive < script.r

It works for me.

Regards
Martin

__
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] [FORGED] Re: Executing an R script and show the plots.

2020-01-29 Thread Martin Møller Skarbiniks Pedersen
On Tue, 28 Jan 2020 at 13:03, Felix Blind  wrote:
>
> I am using Linux and device X11 worked for me in the past. I will check
> your script later and tell you if it works.

[...]

I am using R version 3.6.2 on ubuntu 18.04.3 LTS and the X11-device
when I make plot in the terminal works without problems.



Regards
Martin

__
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 store something not simple in a vector?

2020-01-26 Thread Martin Møller Skarbiniks Pedersen
> I am trying to create a vector to store objects create with gmp::as.bigq().
[...]

> library(gmp)
> V <- vector(typeof(as.bigq(1)), 100) # typeof(as.bigq(1)) is raw
> V[[100]] <- as.bigq(1,2)

I got a solution now. If I use a list instead then everything works.

Regards
Martin M. S. Pedersen

__
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] How to store something not simple in a vector?

2020-01-26 Thread Martin Møller Skarbiniks Pedersen
Hi,

  Sorry for the HTML version in the buttom of this email.
I don't think it is possible to post using gmail without a
html-version in the end.

Anyway to my problem:

I am trying to create a vector to store objects create with gmp::as.bigq().

My first attempt:
library(gmp)
V <- vector("bigq", 100)

My second attempt after understand that I probably need to
examine a bigq with typeof()

library(gmp)
V <- vector(typeof(as.bigq(1)), 100) # typeof(as.bigq(1)) is raw
V[[100]] <- as.bigq(1,2)

With the error message:
Error in V[[100]] <- as.bigq(1, 2) :
  more elements supplied than there are to replace

And now I understand that bigq is stored as raw-bytes and it
is has a length more than 1. Actually:
length(as.raw(as.bitq(1,2))
[1] 16

Please advise.
Thanks a lot.

/Martin M. S. Pedersen

__
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] Conversion from python to R - log-problem

2019-10-27 Thread Martin Møller Skarbiniks Pedersen
Hi,
  I am trying to convert a small python computation to R but my R version
gets the wrong result.

The python code:
import math import log
x = log(2)
for i in range(3,7):
   x = log(i)**x
print(x)
3.14157738716919

My R-version:
x <- log10(2)
for (i in 3:6) {
x <- log10(i)**x
}
print(x)
[1] 0.8207096

=

range(3,7) (Python) is the same as 3:6 (R)
log() (Python) is the same as log10 (R)

What can be wrong?

Regards
Martin M. S. Pedersen

ps. I hope this is plain text without any HTML.

[[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] static vs. lexical scope

2019-09-26 Thread Martin Møller Skarbiniks Pedersen
On Wed, 25 Sep 2019 at 11:03, Francesco Ariis  wrote:
>
> Dear R users/developers,
> while ploughing through "An Introduction to R" [1], I found the
> expression "static scope" (in contraposition to "lexical scope").
>
> I was a bit puzzled by the difference (since e.g. Wikipedia conflates the
> two) until I found this document [2].


I sometimes teach a little R, and they might ask about static/lexical scope.
My short answer is normally that S uses static scoping and R uses
lexical scoping.
And most all modern languages uses lexical scoping.
So if they know Java, C, C# etc. then the scoping rules for R are the same.

I finally says that it is not a full answer but enough for most.

Regards
Martin

__
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 wrong, Python rigth in calcution

2019-09-17 Thread Martin Møller Skarbiniks Pedersen
Hi,
  I don't understand why R computes this wrong. I know I can use gmp and
R will do it correctly.

$ echo '569936821221962380720^3 + (-569936821113563493509)^3 +
(-472715493453327032)^3' | Rscript - [1] -4.373553e+46
Correct answer is 3 and Python can do it:

$ echo
'pow(569936821221962380720,3)+pow(-569936821113563493509,3)+pow(-472715493453327032,3)'|python3
3

[[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] Moving 2nd column into 1st column using R

2019-09-11 Thread Martin Møller Skarbiniks Pedersen
On Tue, 10 Sep 2019 at 04:20, smart hendsome via R-help <
r-help@r-project.org> wrote:
>
> Hi R-user,
> I have a problem regarding R.  How can I move my 2nd column into 1st
column.  For example I have data as below:
>  mydf <- data.frame(matrix(1:6, ncol = 2))
>  mydf
>   X1 X2   1   4   2   5   3   6
> I want move my 2nd column become like this:
>   X11  234   5   6
> Hope anyone can help me. Many thanks.


I am not sure I understand your problem, but try:

mydf <- data.frame(matrix(1:6, ncol = 2, byrow = TRUE))

Regards
Martin

[[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] Reading large files with R

2019-09-01 Thread Martin Møller Skarbiniks Pedersen
On Sun, 1 Sep 2019 at 21:53, Duncan Murdoch 
wrote:

> On 01/09/2019 3:06 p.m., Martin Møller Skarbiniks Pedersen wrote:
> > Hi,
> >
> >I am trying to read yaml-file which is not so large (7 GB) and I have
> > plenty of memory.
>
>

> Individual elements in character vectors have a size limit of 2^31-1.
> The read_yaml() function is putting the whole file into one element, and
> that's failing.
>
>
Oh. I didn't know that. But ok, why would anyone create a
a single character vector so big ...

You probably have a couple of choices:
>
>   - Rewrite read_yaml() so it doesn't try to do that.  This is likely
> hard, because most of the work is being done by a C routine, but it's
> conceivable you could use the stringi::stri_read_raw function to do the
> reading, and convince the C routine to handle the raw value instead of a
> character value.
>

I actually might do that in the future.

  - Find a way to split up your file into smaller pieces.
>

Yes, that will be my first solution. Most YAML is easier to parse without
pasting all lines together (crazy!)


> Duncan Murdoch
>

Thanks for pointing me in the right direction.

/Martin

[[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] Reading large files with R

2019-09-01 Thread Martin Møller Skarbiniks Pedersen
Hi,

  I am trying to read yaml-file which is not so large (7 GB) and I have
plenty of memory.
However I get this error:

$  R --version
R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

library(yaml)
keys <- read_yaml("/data/gpg/gpg-keys.yaml")

Error in paste(readLines(file), collapse = "\n") :
  result would exceed 2^31-1 bytes

2^31-1 is only 2GB.

Please advise,

Regards
Martin

[[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] GMP help - converting rosetta RSA-code to R

2019-08-17 Thread Martin Møller Skarbiniks Pedersen
Hi,
I am trying to make a R version a RosettaCode task involving big number.
More precise, I am trying to convert the c-solution
http://rosettacode.org/wiki/RSA_code#C
to R.

   These two lines in C gives me problems:
const char *plaintext = "Rossetta Code";
mpz_import(pt, strlen(plaintext), 1, 1, 0, 0, plaintext);

I have tried:
library(gmp)
plaintext <- "Rossetta Code"
as.bigz(charToRaw(plaintext))

and
library(gmp)
plaintext <- "Rossetta Code
as.big(split(plaintext,""))

Thanks for any help/suggestions

Regards
Martin M. S. Pedersen

[[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] gmp coredump - where to report?

2019-08-16 Thread Martin Møller Skarbiniks Pedersen
Hi,

  I has trying to convert some raw values into a big number with the
library gmp.
However the library makes R crash. Two questions:

1. Should I report the problem and if yes, where can I report the problem?
2. Is the source code for the R version of GMP somewhere on eg. github, so
I can
post an issue?

Regards
Martin

Here is the code that generate the core-dump:

$ head  -3 ~/R/x86_64-pc-linux-gnu-library/3.6/gmp/DESCRIPTION
Package: gmp
Version: 0.5-13.5
Date: 2019-02-21

$ R --version | head -3
R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

$ R --vanilla

> library(gmp)
> as.bigz(charToRaw("a"))

 *** caught segfault ***
address 0x560e78e1dd4c, cause 'memory not mapped'

[[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] Remove cases with -Inf from a data frame

2019-02-16 Thread Martin Møller Skarbiniks Pedersen
On Sat, 16 Feb 2019 at 16:07, AbouEl-Makarim Aboueissa <
abouelmakarim1...@gmail.com> wrote:
>
> I have a log-transformed data frame with some *-Inf* data values.
>
> *my question: *how to remove all rows with *-Inf* data value from that
data
> frame?


Hi,
  Here is a solution which uses apply.

First a data-frame as input:

set.seed(1)
df <- data.frame(w = sample(c(-Inf,1:20), 10),
 x = sample(c(-Inf,1:20), 10),
 y = sample(c(-Inf,1:20), 10),
 z = sample(c(-Inf,1:20), 10))

df <- df[-(unlist(apply(df, 2, function(x) which(x == -Inf,]

Regards
Martin

[[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] Newbie Question on R versus Matlab/Octave versus C

2019-01-30 Thread Martin Møller Skarbiniks Pedersen
On Mon, 28 Jan 2019 at 22:58, Alan Feuerbacher  wrote:

[...]

> These all have advantages and
> disadvantages for certain tasks, but as I'm new to R I hardly know how
> to evaluate them. Any suggestions?

If you have one-hour left, you
can download  pdf file (8 pages total)
"Getting started in R"
from http://ilustat.com/shared/Getting-Started-in-R.pdf

And then try running the code used in the examples.

Regards
Martin

[[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] Diff'ing 2 strings

2019-01-10 Thread Martin Møller Skarbiniks Pedersen
On Thu, 10 Jan 2019 at 09:23, Gerrit Eichner <
gerrit.eich...@math.uni-giessen.de> wrote:

> Don't you mean ?Rdiff ?
>
>
Oh yes.
The unix/linux command diff uses the rdiff-algorithme and it seems that
Rdiff in R uses the exactly same algorithme.

Regards
Martin

[[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] Diff'ing 2 strings

2019-01-09 Thread Martin Møller Skarbiniks Pedersen
On Sat, Jan 5, 2019, 14:58 Sebastien Bihorel <
sebastien.biho...@cognigencorp.com wrote:

> Hi,
>
> Does R include an equivalent of the linux diff command?
>

yes.
?rdiff

/martin

[[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] very slow "memoise"

2018-11-15 Thread Martin Møller Skarbiniks Pedersen
Hi,

  I want to compute a lot of values and I have tried to use
memoise::memoise to speed-up the computation.
  However it is much slower using the memoised version.

I guess I have misunderstood how to use the package memoise or the
purpose of the package.

The code takes more than 2 minutes to finish but if I remove the line:
"nextstep <- memoise(nextstep)" the code runs in less than 1 second. I
was expecting a
total different result.

Here are the code:

library(memoise)

nextstep <- function(num) {
if (num %% 2 == 0) {
return(num/2)
}
num*3+1
}

nextstep <- memoise(nextstep)

for (idx in 1:1e4) {
steps <- 0
current <- idx
while (current != 1) {
  steps <- steps + 1
  current <- nextstep(current)
}
cat(idx,steps,"\n")
}


Regards
Martin

__
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] prod(NaN, NA) vs. prod(NA, NaN)

2018-07-03 Thread Martin Møller Skarbiniks Pedersen
Hi,
  I am currently using R v3.4.4 and I just discovered this:

> prod(NA, NaN) ; prod(NaN, NA)
[1] NA
[1] NaN

?prod says:
If ‘na.rm’ is ‘FALSE’ an ‘NA’ value in any of the arguments will
 cause a value of ‘NA’ to be returned, otherwise ‘NA’ values are
 ignored.

So according to the manual-page for prod() NA should be returned in both
cases?


However for sum() is opposite is true:
> sum(NA, NaN) ; sum(NaN, NA)
[1] NA
[1] NA

?sum says:
If ‘na.rm’ is ‘FALSE’ an ‘NA’ or ‘NaN’ value in any of the
 arguments will cause a value of ‘NA’ or ‘NaN’ to be returned,
 otherwise ‘NA’ and ‘NaN’ values are ignored.


Maybe the manual for prod() should say the same as sum() that
both NA and NaN can be returned?

Regards
Martin

__
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 bug or misunderstanding

2018-07-02 Thread Martin Møller Skarbiniks Pedersen
Hi,

   Have I found a bug in R? Or misunderstood something about grep() ?

   Case 1 gives the expected output
   Case 2 does not gives the expected output.
   I expected integer(0) also for this case.

case 1:
grep("[:digit:]", "**ABAAbabaabackabaloneaban")
integer(0)

case 2:
grep("[:digit:]", "**ABAAbabaabackabaloneaband")
[1] 1

Regards
Martin

__
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] Unable to take correct Web-snapshot

2018-06-01 Thread Martin Møller Skarbiniks Pedersen
On 1 June 2018 at 15:08, Christofer Bogaso  wrote:
> Hi again,
>
> I use the *webshot* package to take snapshot from Webpage. However, when I
> try to take snapshot from* https://www.coinbase.com/
> *, this fails to take the full snapshot of that
> page.

Yes, that is a general problem with many webshot programs and libraries.

The coinbase page ( and many others ) uses a lot of javascript to generate their
pages and the webshot programs must understand javascript in all
details which is hard.

If you are looking for the coinbase prices you can use their api to
get json instead:

https://api.coinbase.com/v2/prices/spot?currency=USD

Regards
Martin

__
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] rJava garbage collect

2018-02-06 Thread Martin Møller Skarbiniks Pedersen
On 6 February 2018 at 04:34, Benjamin Tyner  wrote:
> Hi
>
> Does rJava offer a way to instruct the JVM to perform a garbage collection?

Do you really, really need to run the garbage collector?

Consider reading:
https://stackoverflow.com/questions/5086800/java-garbage-collection

Regards
Martin

__
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] reading lisp file in R

2018-01-18 Thread Martin Møller Skarbiniks Pedersen
Here are the beginning of a R program.
I hope it can help you writing the rest of the program.

Regards
Martin M. S. Pedersen



filename <- "university.data"


lines <- readLines(filename)

first <- T

for (ALine in lines) {
ALine <- sub("^ +","",ALine)
ALine <- sub(")","",ALine, fixed = T)
if (length(grep("def-instance", ALine))) {
if (first) {
first = F
}
else {
cat(paste(instance,state,control,no_of_students_thous,"\n", sep  = ","))
}
instance <- sub("(def-instance ","",ALine, fixed = T)
next
}
if (length(grep("state ", ALine))) {
state <- sub("(state ","",ALine, fixed = T)
next
}
if (length(grep("control ", ALine))) {
control <- sub("(control ","", ALine, fixed = T)
next
}
if (length(grep("no-of-students thous:", ALine))) {
no_of_students_thous <- ALine
no_of_students_thous <- sub("(no-of-students thous:","", ALine, fixed = T)
next
}
}

[[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] Help making first dataset R package

2018-01-17 Thread Martin Møller Skarbiniks Pedersen
Hi,

  I am trying to make my first R package containing only a single
data.frame and documentation.

  All code can be found at:
https://github.com/MartinMSPedersen/folkeafstemninger

When I check the package I get four warnings.
I will list all warnings in this email because they migth be connected.

1.
* checking if this is a source package ... WARNING
Subdirectory ‘src’ contains:
  convert_from_xml.R
These are unlikely file names for src files.

2.
* checking whether package ‘folkeafstemninger’ can be installed ... WARNING
Found the following significant warnings:
  Warning: no source files found
See ‘/home/mm/gits/folkeafstemninger.Rcheck/00install.out’ for details.

3.
* checking package subdirectories ... WARNING
Subdirectory ‘data’ contains no data sets.
Subdirectory ‘src’ contains no source files.

4.
* checking contents of ‘data’ directory ... WARNING
Files not of a type allowed in a ‘data’ directory:
  ‘folkeafstemninger.Rdata’
Please use e.g. ‘inst/extdata’ for non-R data files


 The raw xml-files I used to create the data.frame is placed under raw/
 The data.frame is saved as data/folkeafstemninger.RData
and
  The R source I wrote to convert the xml-files is placed under src/

Thanks for any help.

Regards
Martin

[[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] roxygen2 error - x$tag operator is invalid for atomic vectors

2018-01-17 Thread Martin Møller Skarbiniks Pedersen
On 17 January 2018 at 14:30, Eric Berger  wrote:

> This is an error message from R.
> For example, if you give the following R commands
> >  a <- 5
> > a$foo
> This will generate the error message:
> Error in a$foo : $ operator is invalid for atomic vectors
>
> So you can search for the string 'x$tag' in your code (or possibly in the
> package).
>

OK thanks.

Something else must be wrong because my package should only contain a
data.frame saved in .RData file

Regards
Martin

[[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] roxygen2 error - x$tag operator is invalid for atomic vectors

2018-01-17 Thread Martin Møller Skarbiniks Pedersen
Hi,

  I am trying to create my first R package.
  I will later today put the files on Github.

  However I gets this error and I can't find any reason for it:

R> roxygen2::roxygenise()
First time using roxygen2. Upgrading automatically...
Error in x$tag : $ operator is invalid for atomic vectors
R>

  Any ideas?

Regards
Martin M. S. Pedersen

[[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 with first S3-class

2018-01-03 Thread Martin Møller Skarbiniks Pedersen
On 3 January 2018 at 08:36, Jeff Newmiller  wrote:
> Function arguments are not pass-by-reference... they are pass-by-value. You 
> need to return the altered object to the caller when you are done messing 
> with it.

Thanks.
Of course. Now it is working.


> Note that R is a data processing language... your example will not scale to 
> real world use cases because you make no use of vectorization to handle 
> multiple accounts.

> It is better to focus on the functional aspect of computing and let the 
> objects carry the results until you have a chance to summarize or plot them.  
> Study the "lm" function and associated print and plot methods.

Thanks for these suggestions. It is very helpful.

Regards
Martin

__
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 with first S3-class

2018-01-02 Thread Martin Møller Skarbiniks Pedersen
Some mistake:

> I expect this output:

[1] 100
Martin
Saldo is: 100

but I get

[1] 0
Martn
Saldo is: 0

__
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 with first S3-class

2018-01-02 Thread Martin Møller Skarbiniks Pedersen
On 3 January 2018 at 00:52, Duncan Murdoch  wrote:
> On 02/01/2018 6:38 PM, Martin Møller Skarbiniks Pedersen wrote:
>>
>> Hi,
>>
>>I am trying to understand S3 classes. I have read several tutorials
>> about
>> the topics but I am still a bit confused. I guess it is because it is
>> so different from
>> Java OOP.
>
>
> What you do below isn't S3.  S3 is a system where the classes are secondary
> to the generic functions.  Methods "belong" to generics, they don't belong
> to classes.  As far as I can see, you hardly make use of S3 methods and
> generics at all.

Here is my second attempt making a S3-class.
But something is wrong with the deposit.account() ? Thanks for any help.

I expect this output:

[1] 0
Martin
Saldo is:  100

but I get this:

[1] 100
Martin
Saldo is:  0

Regards
Martin

account <- function(owner = NULL) {
if (is.null(owner)) stop("Owner can't be NULL")
value <- list(owner = owner, saldo = 0)
attr(value, "class") <- "account"
value
}

balance <- function(obj) { UseMethod("balance") }

balance.account <- function(obj) {
obj$saldo
}

deposit <- function(obj, amount) { UseMethod("deposit") }

deposit.account <- function(obj, amount) {
obj$saldo <- obj$saldo + amount
}

print.account <- function(obj) {
cat(obj$owner, "\n")
cat("Saldo is: ", obj$saldo, "\n")
}

A1 <- account("Martin")
deposit(A1, 100)
balance(A1)
print(A1)

__
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 with first S3-class

2018-01-02 Thread Martin Møller Skarbiniks Pedersen
On 3 January 2018 at 00:52, Duncan Murdoch  wrote:
> On 02/01/2018 6:38 PM, Martin Møller Skarbiniks Pedersen wrote:
>>
>> Hi,
>>
>>I am trying to understand S3 classes. I have read several tutorials
>> about
>> the topics but I am still a bit confused. I guess it is because it is
>> so different from
>> Java OOP.
>
>
> What you do below isn't S3.  S3 is a system where the classes are secondary
> to the generic functions.  Methods "belong" to generics, they don't belong
> to classes.  As far as I can see, you hardly make use of S3 methods and
> generics at all.
>
> For the style you're using, the R6 or R.oo packages might be more suitable.

OK. Thanks, I will rewrite the code.

I read the guide at https://www.programiz.com/r-programming/S3-class
to make the code.
And used the part under: 1.3.2. Local Environment Approach

There is a picture of Wickham and it is sponsored by Datacamp so I was
thinking it was a good place for a guide ?!

Regards
Martin

__
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] Help with first S3-class

2018-01-02 Thread Martin Møller Skarbiniks Pedersen
Hi,

  I am trying to understand S3 classes. I have read several tutorials about
the topics but I am still a bit confused. I guess it is because it is
so different from
Java OOP.

  I have pasted my attempt at creating a bank-account class below and
my problems are:

1. What should be added some plot.default() calls the account$plot() method ?
2. What should the account$plot() be implemented to show some kind of plot ?
3. How can one function inside "me"-list called another function. Eg.
How can account$plot() call account$pastSaldo() ?

Here are my code. Feel free to comment on any aspect of the code.
ps. I hope I have manage to strip HTML.

Regards
Martin



account <- function(owner = NULL) {
thisEnv <- environment()

pastSaldo <- vector()
saldo <- 0
owner <- owner

me <- list(
thisEnv = thisEnv,

 getEnv = function() { return(get("thisEnv", thisEnv)) },

 balance = function() { return(get("saldo", thisEnv)) },

deposit = function(value) {
assign("pastSaldo", append(pastSaldo, saldo), thisEnv)
assign("saldo", saldo + value, thisEnv)
},

withdraw = function(value) {
   assign("pastSaldo", append(pastSaldo, saldo), thisEnv)
   assign("saldo", saldo - value, thisEnv)
},

   pastSaldo = function() {
  return(pastSaldo)
  },

  plot = function() {
 plot.new()
 lines(list(y = pastSaldo, x = seq_along(pastSaldo)))
   }
)
assign('this', me, envir = thisEnv)

class(me) <- append(class(me), "account")
return(me)
}

FirstAccount <- account("Martin")
FirstAccount$deposit(100)
FirstAccount$withdraw(50)
FirstAccount$deposit(200)
FirstAccount$balance()
FirstAccount$pastSaldo()

FirstAccount$plot()

plot(FirstAccount)# fails
plot.account(FirstAccount)   # fails

__
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] Rcpp, dyn.load and C++ problems

2017-12-03 Thread Martin Møller Skarbiniks Pedersen
>
> > edd@bud:~$ r -lRcpp -e'sourceCpp("/tmp/mmsp.cpp")'


???

What is r in this case ? A alias for something ?

Regards
Martin

[[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] Rcpp, dyn.load and C++ problems

2017-12-03 Thread Martin Møller Skarbiniks Pedersen
On 3 December 2017 at 20:19, Dirk Eddelbuettel  wrote:

Hi Dirk,
  Thanks for your answers. I got a few more questions.

>
> 0) Wrong list. Rcpp has its down, rcpp-devel, and I basically do not read
> this and would have missed this were it not for luck.

OK. I did found the rcpp-devel mailing-list.
But I though it was a developers of the rcpp-package.
So it is ok to post beginners questions to rcpp-devel?

>
> 6) Call me crazy but maybe the nine vignettes included with the package?
>

OK. I will print them and read them.

[...]

>
> Then in R:
>
> R> library(Rcpp)
> R> sourceCpp("/tmp/mmsp.cpp")
>

> [...]


>
> _One call_ of sourceCpp() compiles AND links AND loads AND runs the
example R
> code (which is optional).


Basically I was searching for ways to compile to C++ code a single time and
not everything the R code runs.

Like I don't recompile my pure C++ programs everything I run them, only
if I change something.

But that is different with C++ in R? That it is normal to compile the C++
code
for each run?

Regards
Martin

[[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] Rcpp, dyn.load and C++ problems

2017-12-03 Thread Martin Møller Skarbiniks Pedersen
On 3 December 2017 at 05:23, Eric Berger  wrote:

>
> Do a search on "Rcpp calling C++ functions from R"
>

Thanks. However search for "Rcpp calling C++ functions from R" gives a lot
of result but I think
some of them are outdated and others don't agree with each other.

Can you point to a specific good on-line guide for me?

Regards
Martin

[[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] Rcpp, dyn.load and C++ problems

2017-12-03 Thread Martin Møller Skarbiniks Pedersen
On 3 December 2017 at 05:23, Eric Berger  wrote:

> .Call("compute_values_cpp")
> Also, if you were passing arguments to the C++ function you would need to
> declare the function differently.
> Do a search on "Rcpp calling C++ functions from R"
>
>
Hi,
  It is still not working.
  $ ./compile.sh
g++  -I/usr/include/R/ -DNDEBUG   -D_FORTIFY_SOURCE=2
-I/home/tusk/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include -fpic
-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt
-c logistic_map.cpp -o logistic_map.o
g++ -shared -L/usr/lib64/R/lib
-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -o logistic_map.so
logistic_map.o -L/usr/lib64/R/lib -lR

$ readelf -Ws logistic_map.so  | grep -i comp
89: 2a50  2356 FUNCGLOBAL DEFAULT9
_Z18compute_values_cppidid
   141: 2a50  2356 FUNCGLOBAL DEFAULT9
_Z18compute_values_cppidid

$ R
R> dyn.load("logistic_map.so")
R> .Call("compute_values_cpp")
Error in .Call("compute_values_cpp") :
  C symbol name "compute_values_cpp" not in load table

Hmm.



> HTH,
> Eric
>
>
> On Sun, Dec 3, 2017 at 3:06 AM, Martin Møller Skarbiniks Pedersen <
> traxpla...@gmail.com> wrote:
>
>> Hi,
>>
>>   I have written a small C++ function and compile it.
>>   However in R I can't see the function I have defined in C++.
>>   I have read some web-pages about Rcpp and C++ but it is a bit confusion
>> for me.
>>
>> Anyway,
>>   This is the C++-code:
>>
>> #include 
>> using namespace Rcpp;
>>
>> // [[Rcpp::export]]
>> List compute_values_cpp(int totalPoints = 1e5, double angle_increment =
>> 0.01, int radius = 400, double grow = 3.64) {
>>   double xn = 0.5;
>>   double angle = 0.1;
>>   double xn_plus_one, yn_plus_one;
>>   NumericVector x(totalPoints);
>>   NumericVector y(totalPoints);
>>
>>   for (int i=0; i> xn_plus_one = xn*cos(angle)*radius;
>> yn_plus_one = xn*sin(angle)*radius;
>> angle += angle_increment;
>> xn = grow*xn*(1-xn);
>> x[i] = xn_plus_one;
>> y[i] = yn_plus_one;
>>   }
>>   return List::create(Rcpp::Named("x") = x, Rcpp::Named("y") = y);
>> }
>>
>> And I compile it like this:
>> PKG_CXXFLAGS=$(Rscript -e 'Rcpp:::CxxFlags()') \
>> PKG_LIBS=$(Rscript -e 'Rcpp:::LdFlags()')  \
>> R CMD SHLIB logistic_map.cpp
>> without problems and I get a logistic_map.so file as expected.
>>
>> However in R:
>> R> dyn.load("logistic_map.so")
>> R> compute_values_cpp()
>> Error in compute_values_cpp() :
>>   could not find function "compute_values_cpp"
>>
>> Please advise,
>>   What piece of the puzzle is missing?
>>
>> Regards
>> Martin M. S. Pedersen
>>
>> [[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/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>


-- 
Til uvedkommende, der læser med: Der er ingen grund til at læse min
mail. Jeg har intet at gøre med FARC, al-Jihad, al-Qaida, Hamas, Hizb
al-Mujahidin eller ETA. Jeg har aldrig gjort Zakat, går ikke ind for
Istishad, har ikke lavet en bilbombe eller kernevåben og jeg ved
dårligt nok, hvad Al Manar og бомба betyder.  Men tak for den udviste
interesse.

Leve Ligemageriet!
Styrk pøbelvældet!
Bevar misundelsesafgifterne og cafepengene!
Hurra for ældrebyrden!

[[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] Rcpp, dyn.load and C++ problems

2017-12-02 Thread Martin Møller Skarbiniks Pedersen
Hi,

  I have written a small C++ function and compile it.
  However in R I can't see the function I have defined in C++.
  I have read some web-pages about Rcpp and C++ but it is a bit confusion
for me.

Anyway,
  This is the C++-code:

#include 
using namespace Rcpp;

// [[Rcpp::export]]
List compute_values_cpp(int totalPoints = 1e5, double angle_increment =
0.01, int radius = 400, double grow = 3.64) {
  double xn = 0.5;
  double angle = 0.1;
  double xn_plus_one, yn_plus_one;
  NumericVector x(totalPoints);
  NumericVector y(totalPoints);

  for (int i=0; i dyn.load("logistic_map.so")
R> compute_values_cpp()
Error in compute_values_cpp() :
  could not find function "compute_values_cpp"

Please advise,
  What piece of the puzzle is missing?

Regards
Martin M. S. Pedersen

[[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] pls in r

2017-12-01 Thread Martin Møller Skarbiniks Pedersen
Hi,

On 1 December 2017 at 13:17, Margarida Soares 
wrote:

> I am a beginner in R, and I wonder if anyone could help me with a partial
least square regression in R.
> I have looked up the instructions and the manual from Bjorn Mevi and Ron
Wehrens.

So you have read the vignette also ?
https://cran.r-project.org/web/packages/pls/vignettes/pls-manual.pdf

> However, I think I managed to write the script correctly,

You are welcome to post your script here then it would easier to help you.

>
> but I dont understand the output on the R environment, and also how to
decide on the number of components to use (from the RMSEP), and also how to
do a correlation plot.


Maybe this can help you:
https://www.r-bloggers.com/partial-least-squares-regression-in-r/

Regards
Martin

[[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] Help avoiding setting column type two times

2017-11-30 Thread Martin Møller Skarbiniks Pedersen
Hi,
  I think and hope this a good place to ask for code review for a R
beginners?

  I have made a R script which generates a dataset based on 2009 danish
referendum and it does work.

  But I think the code could be better and I would any comments how the
code can be improved.
  At least I would like to know how I avoid converting several of the
columns to factors in the end of the code?

Description of the code:

  It reads a lot of xml-files from ../raw/ and saves a data.frame with
information
from these xml-files.

  In the ../raw/ directiory I have placed the xml-files which I got from
"Statistics Denmark"
  I have also put these xml-files on my website and they can be download
freely from http://20dage.dk/R/referendum-2009/raw.tar.gz

  The code is below but I have also put the code at this place:
http://20dage.dk/R/referendum-2009/convert_from_xml.R

Best Regards
Martin M. S. Pedersen

---
library(xml2)

convert_one_file <- function(url) {
x <- read_xml(url)

Sted <- xml_find_first(x, ".//Sted")
StedType <- xml_attr(Sted, "Type")
StedTekst <- xml_text(Sted)

Parti <- xml_find_all(x, ".//Parti")
PartiId <- xml_attr(Parti, "Id")
PartiBogstav <- xml_attr(Parti, "Bogstav")
PartiNavn <- xml_attr(Parti, "Navn")


StemmerAntal <- xml_attr(Parti, "StemmerAntal")
Stemmeberettigede <- xml_integer(xml_find_first(x,
".//Stemmeberettigede"))
DeltagelsePct <- xml_double(xml_find_first(x, ".//DeltagelsePct"))
IAltGyldigeStemmer <- xml_integer(xml_find_first(x,
".//IAltGyldigeStemmer"))
BlankeStemmer <- xml_integer(xml_find_first(x, ".//BlankeStemmer"))
AndreUgyldigeStemmer <- xml_integer(xml_find_first(x,
".//AndreUgyldigeStemmer"))

data.frame(cbind(StedType, StedTekst, PartiId, PartiBogstav, PartiNavn,
 StemmerAntal, Stemmeberettigede, DeltagelsePct,
IAltGyldigeStemmer,
   BlankeStemmer, AndreUgyldigeStemmer), stringsAsFactors = FALSE)
}

raw_path <- "../raw"
filenames <- dir(path = raw_path, pattern = "fintal_.*", full.names = T)

result <- data.frame(StedType = factor(),
 StedTekst = character(),
 PartiId   = factor(),
 PartiBogstav = factor(),
 PartiNavn= factor(),
 StemmerAntal = integer(),
 Stemmeberettigede = integer(),
 DeltagelsePct = numeric(),
 IAltGyldigeStemmer = integer(),
 BlankeStemmer = integer(),
 AndreUgyldigeStemmer = integer(),
 stringsAsFactors = FALSE)

for (i in 1:length(filenames)) {
#cat(paste0(filenames[i],"\n"))
returnCode <-  tryCatch({
   result <- rbind(result, convert_one_file(filenames[i]))
}, error = function(e) {
   cat(paste0(filenames[i]," failed:\n",e,"\n"))
})
}

result$StedType <- as.factor(result$StedType)
result$PartiId <- as.factor(result$PartiId)
result$PartiBogstav <- as.factor(result$PartiBogstav)
result$PartiNavn <- as.factor(result$PartiNavn)
result$StemmerAntal <- as.integer(result$StemmerAntal)
result$Stemmeberettigede <- as.integer(result$Stemmeberettigede)
result$DeltagelsePct <- as.numeric(result$DeltagelsePct)
result$IAltGyldigeStemmer <- as.integer(result$IAltGyldigeStemmer)
result$BlankeStemmer <- as.integer(result$BlankeStemmer)
result$AndreUgyldigeStemmer <- as.integer(result$AndreUgyldigeStemmer)
str(result)
save(result, file = "folkeafstemning2009.Rdata")

[[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] ggplot2 and tikzDevice : problems with accents

2017-10-22 Thread Martin Møller Skarbiniks Pedersen
On 22 October 2017 at 17:56, Jacques Ropers  wrote:
>
> Hi all,
>
> I can't fathom why the accented "é" in the following ggplot2 graph makes
> R hangs when using tikzdevice,  whereas it works using simple pdf device.
>
[...]

I just tried your code and my R doesn't hang but it does give an TeX-error:

(/usr/share/texlive/texmf-dError in getMetricsFromLatex(TeXMetrics, verbose
= verbose) :
TeX was unable to calculate metrics for the following string
or character:

77

Common reasons for failure include:
  * The string contains a character which is special to LaTeX unless
escaped properly, such as % or $.
  * The string makes use of LaTeX commands provided by a package and
the tikzDevice was not told to load the package.

Regards
Martin

[[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] [FORGED] can't print ggplot with Chinese characters to pdf files

2017-10-20 Thread Martin Møller Skarbiniks Pedersen
On 20 October 2017 at 04:21, John  wrote:
>
> Hi,
>
>Following Paul's instruction, I have installed the Cairo. I tried to
run
> the program, and there is no error message at all. I did see the Chinese
> title in the plot if I ask my RStudio to show the plot (if I type "p1"),
> but the pdf file shows the plots without the Chinese titles.


[...]

>
> cairo_pdf("test_plot_chinese.pdf")
> print(m2)
> dev.off()
>

The help page for cairo_pdf says: "
‘cairo_pdf’ and ‘cairo_ps’ sometimes record _bitmaps_ and not vector
graphics.  On the other hand, they can (on suitable platforms) include a
much
 wider range of UTF-8 glyphs, and embed the fonts used.
"
I am not sure what sometimes means but maybe the fonts are not embedded in
the pdf-file?

try:
embed_fonts('test_plot_chinese.pdf')

note that it might fails if you haven't installed gs (ghostscript)


Regards
Martin

[[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 add make option to package compilation?

2017-09-15 Thread Martin Møller Skarbiniks Pedersen
On 15 September 2017 at 14:13, Duncan Murdoch 
wrote:

> On 15/09/2017 8:11 AM, Martin Møller Skarbiniks Pedersen wrote:
>
>> Hi,
>>
>>I am installing a lot of packages to a new R installation and it takes
>> a
>> long time.
>>However the machine got 4 cpus and most of the packages are written in
>> C/C++.
>>
>>So is it possible to add a -j4 flag to the make command when I use the
>> install.packages() function?
>>That will probably speed up the package installation process 390%.
>>
>
> See the Ncpus argument in ?install.packages.


Thanks.

However it looks like Ncpus=4 tries to compile four R packages at the same
time using one cpu for each packages.

From the documentation:
"
   Ncpus: the number of parallel processes to use for a parallel
  install of more than one source package.  Values greater than
  one are supported if the ‘make’ command specified by
  ‘Sys.getenv("MAKE", "make")’ accepts argument ‘-k -j Ncpus’
"

[[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] How to add make option to package compilation?

2017-09-15 Thread Martin Møller Skarbiniks Pedersen
Hi,

  I am installing a lot of packages to a new R installation and it takes a
long time.
  However the machine got 4 cpus and most of the packages are written in
C/C++.

  So is it possible to add a -j4 flag to the make command when I use the
install.packages() function?
  That will probably speed up the package installation process 390%.

Regards
Martin M. S. Pedersen

[[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] Optimize code to read text-file with digits

2017-09-08 Thread Martin Møller Skarbiniks Pedersen
On 8 September 2017 at 14:37, peter dalgaard  wrote:
>
>
> > On 8 Sep 2017, at 14:03 , peter dalgaard  wrote:
> >
> > x <- scan("~/Downloads/digits.txt")
> > x <- x[-seq(1,22,11)]
>
> ...and, come to think of it, if you really want the 100 random digits:
>
> xx <- c(outer(x,10^(0:4), "%/%")) %% 10
>

Hi Peter,
  Thanks a lot for the answers. I can see that I need to read about outer().
  However I get a different result than expected.

R> x <- scan("digits.txt")
Read 22 items

R> head(x)
[1] 0 10097 32533 76520 13586 34673

R> x <- x[-seq(1,22,11)]
R> head(x)
[1] 10097 32533 76520 13586 34673 54876

R> head(c(outer(x,10^(0:4), "%/%")) %% 10, 10) #
[1] 7 3 0 6 3 6  9 7 2 5

Regards
Martin

[[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] Optimize code to read text-file with digits

2017-09-08 Thread Martin Møller Skarbiniks Pedersen
On 8 September 2017 at 11:25, PIKAL Petr  wrote:

> > Moller Skarbiniks Pedersen

> My program which is slow looks like this:
> >
> > filename <- "digits.txt"
> > lines <- readLines(filename)
>
> why you do not read a file as a whole e.g. by
>
> lines<-read.table("digits.txt")
>

Good idea.

>
> And now I am lost.


[...]


>  Or do you want one big numeric vector from all your numbers?

here you need to read values as character variables
>

Yes. That's what I am looking for.

>
> lines<-read.table("digits.txt", colClasses="character")
> numbers<-as.numeric(unlist(strsplit(as.character(lines[1,]),"")))
> changes first row to numeric vector.
>
>
Do I still need to loop through all lines?
It is maybe even slower now.

numbers <- vector('numeric')
for (i in 1:nrows(lines)) {
  numbers <- c(numbers, as.numeric(unlist(strsplit(as.
character(lines[i,]),""
}


> Anyway, can you explain what is your final goal?
>
>
A numeric vector of length 1 million. Each element should be one digit.


> Cheers
> Petr
>
>
Thanks.
/Martin

[[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] Optimize code to read text-file with digits

2017-09-08 Thread Martin Møller Skarbiniks Pedersen
Hi,

  Every day I try to write some small R programs to improve my R-skills.
  Yesterday I wrote a small program to read the digits from "A Million
Random Digits" from RAND.
  My code works but it is very slow and I guess the code is not optimal.

The digits.txt file downloaded from
https://www.rand.org/pubs/monograph_reports/MR1418.html
contains 2 lines which looks like this:
0   10097 32533  76520 13586  34673 54876  80959 09117  39292 74945
1   37542 04805  64894 74296  24805 24037  20636 10402  00822 91665
2   08422 68953  19645 09303  23209 02560  15953 34764  35080 33606
3   99019 02529  09376 70715  38311 31165  88676 74397  04436 27659
4   12807 99970  80157 36147  64032 36653  98951 16877  12171 76833

My program which is slow looks like this:

filename <- "digits.txt"
lines <- readLines(filename)

numbers <- vector('numeric')
for (i in 1:length(lines)) {

# remove first column
lines[i] <- sub("[^ ]+ +","",lines[i])

# remove spaces
lines[i] <- gsub(" ","",lines[i])

# split the characters and convert them into numbers
numbers <- c(numbers,as.numeric(unlist(strsplit(lines[i],""
}

Thanks for any advice how this program can be improved.

Regards
Martin M. S. Pedersen

[[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] Error in .jnew(“java/io/FileOutputStream”, jFile)

2017-08-22 Thread Martin Møller Skarbiniks Pedersen
On 22 August 2017 at 17:51, Александр Мащенко  wrote:
>
>
> I don't know R absolutely, but I have to do this work for my diploma. So
I'm sorry for strange message below. Please, help me anybody decides this
issue.

[...]

> > write.xlsx(ab_ret,
"C:\\Users\\Sapl\\Desktop\\NATA\\code\\Results\\Created by
R\\10.05.2006\\ab_ret_banks_short_form_10.05.2006.xlsx")
> >
> >Error in .jnew("java/io/FileOutputStream", jFile) :
> >java.io.FileNotFoundException:
> >C:\Users\Sapl\Desktop\NATA\code\Results\Created by
R\10.05.2006\ab_ret_banks_short_form_10.05.2006.xlsx (unreadablesymbols)

I see that you have also posted this answer at Stackoverflow:
https://stackoverflow.com/questions/45782728/error-in-jnewjava-io-fileoutputstream-jfile

My best guess is that the directory:
C:\Users\Sapl\Desktop\NATA\code\Results\Created by R\10.05.2006\
doesn't exist.

Regards
Martin

[[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] Help creating the IBM Randu function

2017-08-14 Thread Martin Møller Skarbiniks Pedersen
Dear all,

  I am trying to learn functions in R and 3D plotting so I decided to try
to plot
the famous bad PRNG Randu from IBM(1).
   However something is not correct in the function I have created.
   First I define the function RANDU like this:

> RANDU <-  function(num) { return (65539*num)%%(2^31) }

and test that it works for a seed of 1:
> RANDU(1)
[1] 65539

but if I want the next value in the sequence I get this number.
> (65539*65539)%%(2^31)
[1] 393225

However using the RANDU function twice doesn't give the same result as
above.

> RANDU(RANDU(1))
[1] 4295360521

I expect these two values to be the same but that is not the case.
393225 should be the correct.

I guess it might be something with local vs. global environment ?!

Please advise and thanks.

Regards
Martin M. S. Pedersen

(1) https://en.wikipedia.org/wiki/RANDU

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