Re: [R] Error Awareness

2021-12-24 Thread Richard O'Keefe
You want to read this:

http://adv-r.had.co.nz/Exceptions-Debugging.html

It describes all the ways that R can report a problem
and all the ways you can catch such a report while still in R.

Let me heartily recommend the whole site, or better yet, the book
https://www.amazon.com/dp/0815384572/ref=cm_sw_su_dp?tag=devtools-20



On Fri, 24 Dec 2021 at 00:14, Stephen H. Dawson, DSL via R-help <
r-help@r-project.org> wrote:

> Hi,
>
>
> I am thinking about awareness of errors when an R script runs.
>
> My concern is I have an error-free script. I run it for months on end
> without problems. Then, something changes somewhere causing an error. My
> wonderment is how R will tell me I had an error in the script, but the
> rest of the script ran without impairment.
>
> QUESTIONS
> What are some of the more helpful options available to an R developer to
> capture errors in a script run?
>
> What are some of the best processes to implement these more helpful
> options?
>
>
> 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] question about for loop

2021-12-24 Thread Kai Yang via R-help
 Thanks Avi. This is a good idea. I'm learning how to create a function in R 
now and may have more questions for you. I really apricate all of your help. 
Wish you have a great holiday and happy new year !Kai
On Friday, December 24, 2021, 04:54:36 PM PST, Avi Gross via R-help 
 wrote:  
 
 Suggestion to consider another approach:

Once various errors are fixed, the program being done basically sounds like
you want to repeat a sequence of actions one per ROW of a data.frame. As it
happens, the action to perform is based on a second data.frame given to
ggplot, with parts dynamically inserted from the variables in one row.

So consider making a function with a name like graph_it() that does what you
want when passed three named arguments. I mean it takes arguments with names
like alpha, beta and gamma and then use the pmap() function (part of the
tidyverse unfortunately in the purr package) along with the function you
want:

Typing:

pmap(.l=mac2, .f=graph_it)

Will implicitly perform your functionality one row after another without an
explicit loop and often faster than nested loops would be. I have used the
technique to replace a deeply nested loop that generates all combinations of
multiple categorical variables (about a million) into a data.frame, then do
something with each one fairly efficiently.

If nothing else, it would make this problem a tad simpler by not needing
subscripts.

-Original Message-
From: R-help  On Behalf Of Andrew Simmons
Sent: Friday, December 24, 2021 5:37 PM
To: Kai Yang 
Cc: R-help Mailing List 
Subject: Re: [R] question about for loop

y, c, and f only exist in the context of mac2 If you want to use them,
you'll have to write mac2$y, mac2$c, or mac2$f (or the [[ versions
mac2[["y"]], mac2[["c"]], or mac2[["f"]]) Combining that with index i would
then look like mac2$y[[i]] or mac2[[i, "y"]]

Also, I think you want to use aes_string instead of aes (since you want
those expressions within aes to be evaluated) Something like this seems to
work for me:


`%>%` <- magrittr::`%>%`


writeLines(FILE <- tempfile(), text =
r"{y,c,f
hwy,cyl,hwy_cyl2
cty,class,cty_class2}")


mac2 <- readr::read_csv(FILE)
for (i in seq_len(nrow(mac2))) {
    ggplt <- ggplot2::mpg %>%
        dplyr::filter(hwy < 35) %>%
        ggplot2::ggplot(
            ggplot2::aes_string(
                x = "displ",
                y = mac2[[i, "y"]],
                color = mac2[[i, "c"]]
            )
        ) +
        ggplot2::geom_point() +
        ggplot2::ylab(mac2[[i, "y"]]) +
        ggplot2::guides(
            color = ggplot2::guide_legend(title = mac2[[i, "c"]])
        )
    ggplot2::ggsave(
        filename = tempfile(
            mac2[[i, "f"]],
            fileext = ".jpg"
        ),
        plot = ggplt,
        width = 9, height = 6, dpi = 1200
    )
}


unlink(FILE)


runs fine on my computer, but might look more like this for you:


library(magrittr)
library(ggplot2)
library(dplyr)
library(readr)


mac2 <- read_csv("C:/temp/mac2.csv")
for (i in seq_len(nrow(mac2))) {
    ggplt <- mpg %>%
        filter(hwy < 35) %>%
        ggplot(
            aes_string(
                x = "displ",
                y = mac2[[i, "y"]],
                color = mac2[[i, "c"]]
            )
        ) +
        geom_point() +
        ylab(mac2[[i, "y"]]) +
        guides(
            color = guide_legend(title = mac2[[i, "c"]])
        )
    ggsave(
        filename = paste0("C:/temp/", mac2[[i, "f"]], ".jpg"),
        plot = ggplt,
        width = 9, height = 6, dpi = 1200
    )
}


try reading through aes and aes_string, and keep in mind that columns in
data frames aren't R variables (where they are in Excel). If you want to use
columns like they are variables, you can try using `with`. For example:


library(magrittr)
library(ggplot2)
library(dplyr)
library(readr)


mac2 <- read_csv("C:/temp/mac2.csv")
for (i in seq_len(nrow(mac2))) {
    with(mac2[i, ], {
        ggplt <- mpg %>%
            filter(hwy < 35) %>%
            ggplot(
                aes_string(
                    x = "displ",
                    y = y,
                    color = c
                )
            ) +
            geom_point() +
            ylab(y) +
            guides(
                color = guide_legend(title = c)
            )
        ggsave(
            filename = paste0("C:/temp/", f, ".jpg"),
            plot = ggplt,
            width = 9, height = 6, dpi = 1200
        )
    })
}




On Fri, Dec 24, 2021 at 4:48 PM Kai Yang via R-help 
wrote:

> Hello Team,
> I create a csv file (mac2) to save parameter values. the file looks like:
>
> y,c,f
> hwy,cyl,hwy_cyl2
> cty,class,cty_class2
>
> Then I load the file into R and apply the parameters y, c, f in for 
> loop, see my code below:
> library(ggplot2)
> library(tidyverse)
> library(readr)
> mac2 <- read_csv("C:/temp/mac2.csv")
> View(mac2)
> for (i in seq(nrow(mac2))){
>  mpg %>%
>    filter(hwy <35) %>%
>    ggplot(aes(x = displ, y = get(y[i]), color = get(c[i]) )) 

Re: [R] question about for loop

2021-12-24 Thread Avi Gross via R-help
Suggestion to consider another approach:

Once various errors are fixed, the program being done basically sounds like
you want to repeat a sequence of actions one per ROW of a data.frame. As it
happens, the action to perform is based on a second data.frame given to
ggplot, with parts dynamically inserted from the variables in one row.

So consider making a function with a name like graph_it() that does what you
want when passed three named arguments. I mean it takes arguments with names
like alpha, beta and gamma and then use the pmap() function (part of the
tidyverse unfortunately in the purr package) along with the function you
want:

Typing:

pmap(.l=mac2, .f=graph_it)

Will implicitly perform your functionality one row after another without an
explicit loop and often faster than nested loops would be. I have used the
technique to replace a deeply nested loop that generates all combinations of
multiple categorical variables (about a million) into a data.frame, then do
something with each one fairly efficiently.

If nothing else, it would make this problem a tad simpler by not needing
subscripts.

-Original Message-
From: R-help  On Behalf Of Andrew Simmons
Sent: Friday, December 24, 2021 5:37 PM
To: Kai Yang 
Cc: R-help Mailing List 
Subject: Re: [R] question about for loop

y, c, and f only exist in the context of mac2 If you want to use them,
you'll have to write mac2$y, mac2$c, or mac2$f (or the [[ versions
mac2[["y"]], mac2[["c"]], or mac2[["f"]]) Combining that with index i would
then look like mac2$y[[i]] or mac2[[i, "y"]]

Also, I think you want to use aes_string instead of aes (since you want
those expressions within aes to be evaluated) Something like this seems to
work for me:


`%>%` <- magrittr::`%>%`


writeLines(FILE <- tempfile(), text =
r"{y,c,f
hwy,cyl,hwy_cyl2
cty,class,cty_class2}")


mac2 <- readr::read_csv(FILE)
for (i in seq_len(nrow(mac2))) {
ggplt <- ggplot2::mpg %>%
dplyr::filter(hwy < 35) %>%
ggplot2::ggplot(
ggplot2::aes_string(
x = "displ",
y = mac2[[i, "y"]],
color = mac2[[i, "c"]]
)
) +
ggplot2::geom_point() +
ggplot2::ylab(mac2[[i, "y"]]) +
ggplot2::guides(
color = ggplot2::guide_legend(title = mac2[[i, "c"]])
)
ggplot2::ggsave(
filename = tempfile(
mac2[[i, "f"]],
fileext = ".jpg"
),
plot = ggplt,
width = 9, height = 6, dpi = 1200
)
}


unlink(FILE)


runs fine on my computer, but might look more like this for you:


library(magrittr)
library(ggplot2)
library(dplyr)
library(readr)


mac2 <- read_csv("C:/temp/mac2.csv")
for (i in seq_len(nrow(mac2))) {
ggplt <- mpg %>%
filter(hwy < 35) %>%
ggplot(
aes_string(
x = "displ",
y = mac2[[i, "y"]],
color = mac2[[i, "c"]]
)
) +
geom_point() +
ylab(mac2[[i, "y"]]) +
guides(
color = guide_legend(title = mac2[[i, "c"]])
)
ggsave(
filename = paste0("C:/temp/", mac2[[i, "f"]], ".jpg"),
plot = ggplt,
width = 9, height = 6, dpi = 1200
)
}


try reading through aes and aes_string, and keep in mind that columns in
data frames aren't R variables (where they are in Excel). If you want to use
columns like they are variables, you can try using `with`. For example:


library(magrittr)
library(ggplot2)
library(dplyr)
library(readr)


mac2 <- read_csv("C:/temp/mac2.csv")
for (i in seq_len(nrow(mac2))) {
with(mac2[i, ], {
ggplt <- mpg %>%
filter(hwy < 35) %>%
ggplot(
aes_string(
x = "displ",
y = y,
color = c
)
) +
geom_point() +
ylab(y) +
guides(
color = guide_legend(title = c)
)
ggsave(
filename = paste0("C:/temp/", f, ".jpg"),
plot = ggplt,
width = 9, height = 6, dpi = 1200
)
})
}




On Fri, Dec 24, 2021 at 4:48 PM Kai Yang via R-help 
wrote:

> Hello Team,
> I create a csv file (mac2) to save parameter values. the file looks like:
>
> y,c,f
> hwy,cyl,hwy_cyl2
> cty,class,cty_class2
>
> Then I load the file into R and apply the parameters y, c, f in for 
> loop, see my code below:
> library(ggplot2)
> library(tidyverse)
> library(readr)
> mac2 <- read_csv("C:/temp/mac2.csv")
> View(mac2)
> for (i in seq(nrow(mac2))){
>   mpg %>%
> filter(hwy <35) %>%
> ggplot(aes(x = displ, y = get(y[i]), color = get(c[i]) )) +
> geom_point()+
> ylab(y[i]) +
> guides(color = guide_legend(title = c[i])) 
> ggsave(paste0("c:/temp/",f[i],".jpg"),width = 9, height = 6, dpi = 
> 1200, units = "in") }
>
> but I got an error message: "Error in dots_list(..., title = title, 
> subtitle = subtitle, caption = ca

Re: [R] question about for loop

2021-12-24 Thread Kai Yang via R-help
 Thanks Andrew. This is super helpful. --- Kai
On Friday, December 24, 2021, 02:37:14 PM PST, Andrew Simmons 
 wrote:  
 
 y, c, and f only exist in the context of mac2If you want to use them, you'll 
have to write mac2$y, mac2$c, or mac2$f (or the [[ versions mac2[["y"]], 
mac2[["c"]], or mac2[["f"]])Combining that with index i would then look like 
mac2$y[[i]] or mac2[[i, "y"]]
Also, I think you want to use aes_string instead of aes (since you want those 
expressions within aes to be evaluated)Something like this seems to work for me:

`%>%` <- magrittr::`%>%`


writeLines(FILE <- tempfile(), text =
r"{y,c,f
hwy,cyl,hwy_cyl2
cty,class,cty_class2}")


mac2 <- readr::read_csv(FILE)
for (i in seq_len(nrow(mac2))) {
    ggplt <- ggplot2::mpg %>%
        dplyr::filter(hwy < 35) %>%
        ggplot2::ggplot(
            ggplot2::aes_string(
                x = "displ",
                y = mac2[[i, "y"]],
                color = mac2[[i, "c"]]
            )
        ) +
        ggplot2::geom_point() +
        ggplot2::ylab(mac2[[i, "y"]]) +
        ggplot2::guides(
            color = ggplot2::guide_legend(title = mac2[[i, "c"]])
        )
    ggplot2::ggsave(
        filename = tempfile(
            mac2[[i, "f"]],
            fileext = ".jpg"
        ),
        plot = ggplt,
        width = 9, height = 6, dpi = 1200
    )
}


unlink(FILE)


runs fine on my computer, but might look more like this for you:

library(magrittr)
library(ggplot2)
library(dplyr)
library(readr)


mac2 <- read_csv("C:/temp/mac2.csv")
for (i in seq_len(nrow(mac2))) {
    ggplt <- mpg %>%
        filter(hwy < 35) %>%
        ggplot(
            aes_string(
                x = "displ",
                y = mac2[[i, "y"]],
                color = mac2[[i, "c"]]
            )
        ) +
        geom_point() +
        ylab(mac2[[i, "y"]]) +
        guides(
            color = guide_legend(title = mac2[[i, "c"]])
        )
    ggsave(
        filename = paste0("C:/temp/", mac2[[i, "f"]], ".jpg"),
        plot = ggplt,
        width = 9, height = 6, dpi = 1200
    )
}


try reading through aes and aes_string, and keep in mind that columns in data 
frames aren't R variables (where they are in Excel). If you want to use columns 
like they are variables, you can try using `with`. For example:

library(magrittr)
library(ggplot2)
library(dplyr)
library(readr)


mac2 <- read_csv("C:/temp/mac2.csv")
for (i in seq_len(nrow(mac2))) {
    with(mac2[i, ], {
        ggplt <- mpg %>%
            filter(hwy < 35) %>%
            ggplot(
                aes_string(
                    x = "displ",
                    y = y,
                    color = c
                )
            ) +
            geom_point() +
            ylab(y) +
            guides(
                color = guide_legend(title = c)
            )
        ggsave(
            filename = paste0("C:/temp/", f, ".jpg"),
            plot = ggplt,
            width = 9, height = 6, dpi = 1200
        )
    })
}




On Fri, Dec 24, 2021 at 4:48 PM Kai Yang via R-help  
wrote:

Hello Team,
I create a csv file (mac2) to save parameter values. the file looks like:

y,c,f
hwy,cyl,hwy_cyl2
cty,class,cty_class2

Then I load the file into R and apply the parameters y, c, f in for loop, see 
my code below:
library(ggplot2)
library(tidyverse)
library(readr)
mac2 <- read_csv("C:/temp/mac2.csv")
View(mac2)
for (i in seq(nrow(mac2))){
  mpg %>%
    filter(hwy <35) %>% 
    ggplot(aes(x = displ, y = get(y[i]), color = get(c[i]) )) + 
    geom_point()+
    ylab(y[i]) +                              
    guides(color = guide_legend(title = c[i]))    
ggsave(paste0("c:/temp/",f[i],".jpg"),width = 9, height = 6, dpi = 1200, units 
= "in")
}

but I got an error message: "Error in dots_list(..., title = title, subtitle = 
subtitle, caption = caption,  :  object 'y' not found"
Does anyone know how to fix the problem?
Thanks,
Kai


        [[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] question about for loop

2021-12-24 Thread Andrew Simmons
y, c, and f only exist in the context of mac2
If you want to use them, you'll have to write mac2$y, mac2$c, or mac2$f (or
the [[ versions mac2[["y"]], mac2[["c"]], or mac2[["f"]])
Combining that with index i would then look like mac2$y[[i]] or mac2[[i,
"y"]]

Also, I think you want to use aes_string instead of aes (since you want
those expressions within aes to be evaluated)
Something like this seems to work for me:


`%>%` <- magrittr::`%>%`


writeLines(FILE <- tempfile(), text =
r"{y,c,f
hwy,cyl,hwy_cyl2
cty,class,cty_class2}")


mac2 <- readr::read_csv(FILE)
for (i in seq_len(nrow(mac2))) {
ggplt <- ggplot2::mpg %>%
dplyr::filter(hwy < 35) %>%
ggplot2::ggplot(
ggplot2::aes_string(
x = "displ",
y = mac2[[i, "y"]],
color = mac2[[i, "c"]]
)
) +
ggplot2::geom_point() +
ggplot2::ylab(mac2[[i, "y"]]) +
ggplot2::guides(
color = ggplot2::guide_legend(title = mac2[[i, "c"]])
)
ggplot2::ggsave(
filename = tempfile(
mac2[[i, "f"]],
fileext = ".jpg"
),
plot = ggplt,
width = 9, height = 6, dpi = 1200
)
}


unlink(FILE)


runs fine on my computer, but might look more like this for you:


library(magrittr)
library(ggplot2)
library(dplyr)
library(readr)


mac2 <- read_csv("C:/temp/mac2.csv")
for (i in seq_len(nrow(mac2))) {
ggplt <- mpg %>%
filter(hwy < 35) %>%
ggplot(
aes_string(
x = "displ",
y = mac2[[i, "y"]],
color = mac2[[i, "c"]]
)
) +
geom_point() +
ylab(mac2[[i, "y"]]) +
guides(
color = guide_legend(title = mac2[[i, "c"]])
)
ggsave(
filename = paste0("C:/temp/", mac2[[i, "f"]], ".jpg"),
plot = ggplt,
width = 9, height = 6, dpi = 1200
)
}


try reading through aes and aes_string, and keep in mind that columns in
data frames aren't R variables (where they are in Excel). If you want to
use columns like they are variables, you can try using `with`. For example:


library(magrittr)
library(ggplot2)
library(dplyr)
library(readr)


mac2 <- read_csv("C:/temp/mac2.csv")
for (i in seq_len(nrow(mac2))) {
with(mac2[i, ], {
ggplt <- mpg %>%
filter(hwy < 35) %>%
ggplot(
aes_string(
x = "displ",
y = y,
color = c
)
) +
geom_point() +
ylab(y) +
guides(
color = guide_legend(title = c)
)
ggsave(
filename = paste0("C:/temp/", f, ".jpg"),
plot = ggplt,
width = 9, height = 6, dpi = 1200
)
})
}




On Fri, Dec 24, 2021 at 4:48 PM Kai Yang via R-help 
wrote:

> Hello Team,
> I create a csv file (mac2) to save parameter values. the file looks like:
>
> y,c,f
> hwy,cyl,hwy_cyl2
> cty,class,cty_class2
>
> Then I load the file into R and apply the parameters y, c, f in for loop,
> see my code below:
> library(ggplot2)
> library(tidyverse)
> library(readr)
> mac2 <- read_csv("C:/temp/mac2.csv")
> View(mac2)
> for (i in seq(nrow(mac2))){
>   mpg %>%
> filter(hwy <35) %>%
> ggplot(aes(x = displ, y = get(y[i]), color = get(c[i]) )) +
> geom_point()+
> ylab(y[i]) +
> guides(color = guide_legend(title = c[i]))
> ggsave(paste0("c:/temp/",f[i],".jpg"),width = 9, height = 6, dpi = 1200,
> units = "in")
> }
>
> but I got an error message: "Error in dots_list(..., title = title,
> subtitle = subtitle, caption = caption,  :  object 'y' not found"
> Does anyone know how to fix the problem?
> Thanks,
> Kai
>
>
> [[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.


[R] question about for loop

2021-12-24 Thread Kai Yang via R-help
Hello Team,
I create a csv file (mac2) to save parameter values. the file looks like:

y,c,f
hwy,cyl,hwy_cyl2
cty,class,cty_class2

Then I load the file into R and apply the parameters y, c, f in for loop, see 
my code below:
library(ggplot2)
library(tidyverse)
library(readr)
mac2 <- read_csv("C:/temp/mac2.csv")
View(mac2)
for (i in seq(nrow(mac2))){
  mpg %>%
    filter(hwy <35) %>% 
    ggplot(aes(x = displ, y = get(y[i]), color = get(c[i]) )) + 
    geom_point()+
    ylab(y[i]) +                              
    guides(color = guide_legend(title = c[i]))    
ggsave(paste0("c:/temp/",f[i],".jpg"),width = 9, height = 6, dpi = 1200, units 
= "in")
}

but I got an error message: "Error in dots_list(..., title = title, subtitle = 
subtitle, caption = caption,  :  object 'y' not found"
Does anyone know how to fix the problem?
Thanks,
Kai


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] .Rdata not loading

2021-12-24 Thread Rich Shepard

On Fri, 24 Dec 2021, Jeff Newmiller wrote:


The qsave/qread functions from the qs package are functionally
interchangeable with saveRDS/readRDS, but faster and create smaller files.
A simple

 if ( file.exists( "obj1.qs" ) ) {
   obj1 <- qread( "onj1.qs" )
 } else {
   obj1 <- compute_obj1()
   qsave( obj1, "obj1.qs" )
 }
can be used


Jeff,

I understand that with qs each R object needs to be in a separate .qs file
rather than having all of them in a single file such as .RData or .rda.


... but there are various caching packages [1] for ad-hoc use that
attempt to determine when a computation is out of date better than the
existence of a file (that you have to manually delete if you want to
recompute) but they may either fail to notice relevant changes or
recompute unnecessarily.


I'll look closely at caching-in-R.


I have in the last couple of months found that the targets package [2]
seems to excel at balancing these concerns and regularly use it now for
large or complicated analyses.


I read the targets users manual and vignettes and found that it's much too
complex for my simple needs. I consider my projects to be subjectively
small and uncomplicated. Each of my projects are unique and one-off.

Thanks and happy holiday,

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] .Rdata not loading

2021-12-24 Thread Rich Shepard

On Fri, 24 Dec 2021, Rui Barradas wrote:


Can section Adoption of this Library of Congress link
https://www.loc.gov/preservation/digital/formats/fdd/fdd000470.shtml
help? I'm really not sure.


Rui,

After reading that interesting page I don't see how it helps me. I think
that re-running all my scripts, in order, is needed. As this is the first
time I've started R and not have the saved workspace automatically loaded
I'll keep saving the workspace prior to exiting. Should this happen again
I'll change to using an alternative, probably quick sequense (qs). Having
all scripts makes re-creating the workspace a small time investment.

Happy holiday to you and yours,

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] .Rdata not loading

2021-12-24 Thread Jeff Newmiller
The qsave/qread functions from the qs package are functionally interchangeable 
with saveRDS/readRDS, but faster and create smaller files. A simple

  if ( file.exists( "obj1.qs" ) ) {
obj1 <- qread( "onj1.qs" )
  } else {
obj1 <- compute_obj1()
qsave( obj1, "obj1.qs" )
  }

can be used but there are various caching packages [1] for ad-hoc use that 
attempt to determine when a computation is out of date better than the 
existence of a file (that you have to manually delete if you want to recompute) 
but they may either fail to notice relevant changes or recompute unnecessarily. 
 I have in the last couple of months found that the targets package [2] seems 
to excel at balancing these concerns and regularly use it now for large or 
complicated analyses. You can build the _targets.R file by hand or use a 
targets markdown file to build it for you and let you document your  process as 
you go. Once all objects are computed and in the cache then you can build 
reporting scripts that generate plots and tabular output that retrieve the data 
as needed.

[1] https://joshuacook.netlify.app/post/caching-in-r/

[2] https://books.ropensci.org/targets/

On December 24, 2021 8:31:21 AM PST, Rich Shepard  
wrote:
>On Fri, 24 Dec 2021, Adrian Dușa wrote:
>
>> Package admisc has a function called obj.rda(), which returns the names of
>> the objects from an .Rdata file. Not sure how it handles corrupt .Rdata
>> files, but should generally give an idea about what's inside.
>
>Adrian,
>
>Thank you. I know what dataframes and plots should be in there. I'll
>probably end up running all scripts again, in sequence, and reconstructing
>what's lost. And, I'm experimenting with qs (quick save) to understand what
>it does and how to use it.
>
>Regards,
>
>Rich
>
>__
>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.

-- 
Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] .Rdata not loading

2021-12-24 Thread Rui Barradas

Hello,

Can section Adoption of this Library of Congress link


https://www.loc.gov/preservation/digital/formats/fdd/fdd000470.shtml


help? I'm really not sure.


Happy Holidays,

Rui Barradas

Às 16:31 de 24/12/21, Rich Shepard escreveu:

On Fri, 24 Dec 2021, Adrian Dușa wrote:

Package admisc has a function called obj.rda(), which returns the 
names of

the objects from an .Rdata file. Not sure how it handles corrupt .Rdata
files, but should generally give an idea about what's inside.


Adrian,

Thank you. I know what dataframes and plots should be in there. I'll
probably end up running all scripts again, in sequence, and reconstructing
what's lost. And, I'm experimenting with qs (quick save) to understand what
it does and how to use it.

Regards,

Rich

__
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@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 Awareness

2021-12-24 Thread Avi Gross via R-help
Stephen,

I actually happen to like debates and abstractions especially covering multiple 
languages and domains but not HERE. As you note, some people created this forum 
for several purposes but the word HELP should provide a clue as to the main 
purpose. It is not meant to teach R or do homework for people but is somewhere 
in between and elsewhere. Ideally, it helps people who are a bit stuck 
somewhere but can already program and need a fresh pair of eyes or some domain 
knowledge to get over that problem and continue. The Posting Guide spells it 
out.

There is some latitude but stretching it too far can be a problem. Plenty of 
people do and I suppose some of my longer messages also make me guilty. And 
people who repeatedly ask for one thing after another, often are those who 
should do some independent study before working on the problems as the people 
who volunteer here generally do not want a full-time unpaid tutoring job.

If you can find another forum that welcomes lively debates on what is good or 
bad about a language like R or discusses alternative ways to do things or bet 
practices and so on, or what new features might be helpful, let me know and I 
might join.

For now, I think I will step aside and focus my efforts elsewhere.

-Original Message-
From: Stephen H. Dawson, DSL  
Sent: Friday, December 24, 2021 9:49 AM
To: Avi Gross ; 'r-help mailing list' 

Subject: Re: [R] Error Awareness

Thank you, Avi. I appreciate your reply. I agree maturing code is the best move 
to answer this interrogatory. I express deep thanks for contextualizing your 
response.

I also agree with you responses are becoming a pattern here. A post of an 
open-ended question regarding either a conceptual or stylistic topic is 
answered pervasively with linear thinking. This combination is a mismatch of 
context.

https://www.r-project.org/posting-guide.html

I summarize reading in the R Posting Guide, which is written in English, the 
recommendation to state a specific question involving specific R functionality. 
I read nothing in the R Posting Guide where open-ended questions are disallowed 
or even discouraged. Furthermore, I cannot imagine not posting either 
conceptual or stylistic questions to any practice group. If learning is not 
accomplished by open-ended questions, then there is nothing left other than 
closed-ended (direct) questions.

All the same, the benefit of gaining either tacit understanding or wisdom to 
use the R language by way of open-ended questioning is not found in the R 
Posting Guide as it is either written or practiced. This reality impairs the 
ability to learn about a dialogue member's thought process. It also impairs the 
ability to ever be able to one day offer either contract or employment work to 
anyone demonstrating both intimate knowledge of the R language and having the 
wisdom to implement it effectively.

It is inappropriate to recommend modifications to the R Posting Guide in this 
discussion, as it would be out of scope. So, I will not do it.

I close this dialogue as resolved. It is best to post any further discussion of 
this interrogatory in a new dialogue to avoid violating the R Posting Guide 
requirement of the stated Latin term ad hominem.

  https://www.dictionary.com/browse/ad-hominem

  https://en.wikipedia.org/wiki/Ad_hominem#Terminology


  Kindest Regards,
*Stephen Dawson, DSL*
/Executive Strategy Consultant/
Business & Technology
+1 (865) 804-3454
http://www.shdawson.com 


On 12/23/21 10:28 PM, Avi Gross via R-help wrote:
> Stephen,
>
> It is becoming a pattern here.
>
> You have been told R allows ways to check for errors as the code is 
> interpreted and this DOES NOT distinguish between development aspects 
> and in the field. It does not matter if a problem is external like a 
> required file not being in place or having a new name or whatever.
>
> Anything that may go wrong can be handled in quite a few ways. Some 
> are fairly obvious, such as checking if an expected  list or vector or 
> whatever is returned that is empty or not set or is the wrong data 
> type or contains some NA or negative numbers and on and on. All kinds 
> of IF statements and checks are a way to deal with these and you 
> decide whether to make some kind of fix or abort.
>
> But obviously if the error happens outside your code (and sometimes 
> also
> within) you can use various ways R provides to intercept the error and 
> do something. Heck, people often use this in advance as a programming 
> tactic such as using try() or tryCatch() to something like try to open 
> file1 in the current directory and if that fails, in a specified 
> directory and maybe if that fails, get it from file2 or maybe standard input 
> ...
>
> Well-written code that wants to be bullet-proof will often be a bit 
> bloated as it regularly stops and checks not only for all kinds of 
> error conditions but also checks if the variables being used are in 
> the proper form

Re: [R] .Rdata not loading

2021-12-24 Thread Rich Shepard

On Fri, 24 Dec 2021, Adrian Dușa wrote:


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


Adrian,

Thank you. I know what dataframes and plots should be in there. I'll
probably end up running all scripts again, in sequence, and reconstructing
what's lost. And, I'm experimenting with qs (quick save) to understand what
it does and how to use it.

Regards,

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] .Rdata not loading

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

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

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

Hth,
Adrian

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] .Rdata not loading

2021-12-24 Thread Rich Shepard

On Fri, 24 Dec 2021, Rasmus Liland wrote:


If you want to look at Rdata-files in a quick way in the
terminal, use this little gem in your .zshrc.local:

readrdata() { Rscript -e "options(width=$COLUMNS); load('$1'); sapply(ls(), get, 
simplify=F)" | less }


Rasmus,

I use bash, not zsh. And running the readdata() command in R produces no
output.

Thanks for the thought,

Rich

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

2021-12-24 Thread Stephen H. Dawson, DSL via R-help
Thank you, Avi. I appreciate your reply. I agree maturing code is the 
best move to answer this interrogatory. I express deep thanks for 
contextualizing your response.


I also agree with you responses are becoming a pattern here. A post of 
an open-ended question regarding either a conceptual or stylistic topic 
is answered pervasively with linear thinking. This combination is a 
mismatch of context.


https://www.r-project.org/posting-guide.html

I summarize reading in the R Posting Guide, which is written in English, 
the recommendation to state a specific question involving specific R 
functionality. I read nothing in the R Posting Guide where open-ended 
questions are disallowed or even discouraged. Furthermore, I cannot 
imagine not posting either conceptual or stylistic questions to any 
practice group. If learning is not accomplished by open-ended questions, 
then there is nothing left other than closed-ended (direct) questions.


All the same, the benefit of gaining either tacit understanding or 
wisdom to use the R language by way of open-ended questioning is not 
found in the R Posting Guide as it is either written or practiced. This 
reality impairs the ability to learn about a dialogue member's thought 
process. It also impairs the ability to ever be able to one day offer 
either contract or employment work to anyone demonstrating both intimate 
knowledge of the R language and having the wisdom to implement it 
effectively.


It is inappropriate to recommend modifications to the R Posting Guide in 
this discussion, as it would be out of scope. So, I will not do it.


I close this dialogue as resolved. It is best to post any further 
discussion of this interrogatory in a new dialogue to avoid violating 
the R Posting Guide requirement of the stated Latin term ad hominem.


 https://www.dictionary.com/browse/ad-hominem

 https://en.wikipedia.org/wiki/Ad_hominem#Terminology


 Kindest Regards,
*Stephen Dawson, DSL*
/Executive Strategy Consultant/
Business & Technology
+1 (865) 804-3454
http://www.shdawson.com 


On 12/23/21 10:28 PM, Avi Gross via R-help wrote:

Stephen,

It is becoming a pattern here.

You have been told R allows ways to check for errors as the code is
interpreted and this DOES NOT distinguish between development aspects and in
the field. It does not matter if a problem is external like a required file
not being in place or having a new name or whatever.

Anything that may go wrong can be handled in quite a few ways. Some are
fairly obvious, such as checking if an expected  list or vector or whatever
is returned that is empty or not set or is the wrong data type or contains
some NA or negative numbers and on and on. All kinds of IF statements and
checks are a way to deal with these and you decide whether to make some kind
of fix or abort.

But obviously if the error happens outside your code (and sometimes also
within) you can use various ways R provides to intercept the error and do
something. Heck, people often use this in advance as a programming tactic
such as using try() or tryCatch() to something like try to open file1 in the
current directory and if that fails, in a specified directory and maybe if
that fails, get it from file2 or maybe standard input ...

Well-written code that wants to be bullet-proof will often be a bit bloated
as it regularly stops and checks not only for all kinds of error conditions
but also checks if the variables being used are in the proper format and
range before being passed to functions that might break, is say you told it
to use a correlation above 1. It also decides to intelligently deal with the
errors, when possible.

I have written code that called a statistical analysis (lavaan)  function
hundreds of thousands of times on randomly generated data and it worked
fine, except occasionally it broke. As I tended to run it overnight, it was
a pain to wake up and find it had crashed. No, I am not aware why it
crashed, but it could have been something as simple as a matrix that could
not be inverted. But for my purposes, it did not matter as what I would be
happy to get is knowing it failed, marking associated rows of a data.frame
accordingly, and filtering out the results in later analyses. So, I wrapped
not only this call but some others as described above and intercepted the
rare problem and dealt with it and let my program continue overnight.

Clearly if you expect anomalies to be rare, this is extra overhead. But if
things do happen, then your code is not robust enough.

-Original Message-
From: R-help  On Behalf Of Stephen H. Dawson,
DSL via R-help
Sent: Thursday, December 23, 2021 11:17 AM
To: Bert Gunter 
Cc: R-help 
Subject: Re: [R] Error Awareness

Hi Bert,


Thanks for the reply.

The use case I presented involves working code, not diagnosing a script in
development.

The concern is running a script where something changes outside of the
script, as I stated. An example of a change is a data source chan

Re: [R] .Rdata not loading

2021-12-24 Thread Rasmus Liland
Dear Rich,

If you want to look at Rdata-files in a quick way in the 
terminal, use this little gem in your .zshrc.local:

readrdata() { Rscript -e "options(width=$COLUMNS); load('$1'); sapply(ls(), 
get, simplify=F)" | less }

Merry Christmas!

Best,
Rasmus

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] .Rdata not loading

2021-12-24 Thread Rich Shepard

On Thu, 23 Dec 2021, Bill Dunlap wrote:


Three things you might try using R (and show the results in this email
thread):


Bill,


* load(verbose=TRUE, ".RData") # see how far it gets before stopping

load(verbose=TRUE, ".RData")
Loading objects:
  all_turb_plot
  disc_all
Error in load(verbose = TRUE, ".RData") :
  ReadItem: unknown type 0, perhaps written by later version of R


* file.info(normalizePath(".RData")) # is this the file you think it is?

file.info(normalizePath(".RData"))

   size
/home/rshepard/documents/monographs/regulatory-science/npdes-wqbel/analyses/.RData
 28074080

   isdir
/home/rshepard/documents/monographs/regulatory-science/npdes-wqbel/analyses/.RData
 FALSE

   mode
/home/rshepard/documents/monographs/regulatory-science/npdes-wqbel/analyses/.RData
  644

 mtime
/home/rshepard/documents/monographs/regulatory-science/npdes-wqbel/analyses/.RData
 2021-12-22 15:32:59

 ctime
/home/rshepard/documents/monographs/regulatory-science/npdes-wqbel/analyses/.RData
 2021-12-22 15:32:59

 atime
/home/rshepard/documents/monographs/regulatory-science/npdes-wqbel/analyses/.RData
 2021-12-24 06:23:33

uid
/home/rshepard/documents/monographs/regulatory-science/npdes-wqbel/analyses/.RData
 1000

   gid
/home/rshepard/documents/monographs/regulatory-science/npdes-wqbel/analyses/.RData
 100

  uname
/home/rshepard/documents/monographs/regulatory-science/npdes-wqbel/analyses/.RData
 rshepard

   grname
/home/rshepard/documents/monographs/regulatory-science/npdes-wqbel/analyses/.RData
  users


* dput(readBin(".RData", what=raw(), n=100))

dput(readBin(".RData", what=raw(), n=100))
as.raw(c(0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x03, 0xec, 0xfd, 0x09, 0x9c, 0x24, 0x47, 0x79, 0xe7, 0x8d, 0x67, 
0x9f, 0x73, 0x68, 0xa4, 0x19, 0x8d, 0xa4, 0xd1, 0x81, 0x84, 0x5a, 
0x07, 0x58, 0x02, 0xd4, 0x74, 0xf7, 0xdc, 0x18, 0xd4, 0xc3, 0x21, 
0x61, 0xec, 0xb1, 0x60, 0x41, 0xe2, 0xb2, 0xf0, 0xb8, 0x7a, 0xba, 
0xa7, 0xd5, 0xa8, 0x2f, 0x77, 0xf7, 0x68, 0xa6, 0x05, 0x86, 0x59, 
0xc0, 0x60, 0x03, 0xb6, 0x58, 0x63, 0x9b, 0xe3, 0xc5, 0x17, 0x5e, 
0x1f, 0x8b, 0x4f, 0xfe, 0xde, 0x77, 0x7d, 0xbc, 0x3e, 0x64, 0xf0, 
0x1a, 0x1b, 0x6c, 0x2f, 0xa7, 0x0d, 0x98, 0x43, 0x20, 0x83, 0x39, 
0x0c, 0x6e, 0x63))



And a fourth thing to do:
* dput(tail(n=20, readBin(".RData", what=raw(), n=file.size(".RData"

dput(tail(n=20, readBin(".RData", what=raw(), n=file.size(".RData"
as.raw(c(0x5c, 0xae, 0x97, 0x5f, 0x1d, 0x9d, 0x2d, 0x1f, 0xad, 
0xa8, 0xf5, 0x5f, 0x8f, 0x47, 0xdd, 0x56, 0x60, 0xd5, 0x70, 0x3c

))

I hope this explains why .RData contains only two files when there were
30 or more when I saved it.

Thanks,

Rich

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