Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3214650
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:05:09+00:00 2026-05-17T15:05:09+00:00

Let me add another scoping problem in R, this time with the snowfall package.

  • 0

Let me add another scoping problem in R, this time with the snowfall package. If I define a function in my global environment, and I try to use that one later in an sfApply() inside another function, my first function isn’t found any more :

#Runnable code. Don't forget to stop the cluster with sfStop()
require(snowfall)
sfInit(parallel=TRUE,cpus=3)

func1 <- function(x){
    y <- x+1
    y
}

func2 <- function(x){
    y <- sfApply(x,2,function(i) func1(i) )
    y
}

y <- matrix(1:10,ncol=2)
func2(y)
sfStop()

This gives :

> func2(y)
Error in checkForRemoteErrors(val) : 
  2 nodes produced errors; first error: could not find function "func1"

If I nest my function inside the other function however, it works. It also works when I use the sfApply() in the global environment. Thing is, I don’t want to nest my function func1 inside that function2, as that would cause that func1 is defined many times (func2 is used in a loop-like structure).

I’ve tried already simplifying the code to get rid of the double looping, but that’s quite impossible due to the nature of the problem. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:05:09+00:00Added an answer on May 17, 2026 at 3:05 pm

    I think you want to sfExport(func1), though I’m not sure if you need to do it in your .GlobalEnv or inside of func2. Hope that helps…

    > y <- matrix(1:10,ncol=2)
    
    > sfExport(list=list("func1"))
    
    > func2(y)
         [,1] [,2]
    [1,]    2    7
    [2,]    3    8
    [3,]    4    9
    [4,]    5   10
    [5,]    6   11
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to add another function procC in here so that the sequence
How do I add let's say something like ajax=1 to all links on my
Im looking for a simple bit of code that will let me add the
Is their any notifier which let's you add specific build in the notifier. Right
Let's say we have a service to add a new hotel: > POST /hotel
Let's say I have defined a route: routes.Add(new Route(Users/{id}, new MvcRouteHandler()) { Defaults =
Let's say I have a site where Users can add Entries through admin panel.
Let's say I've got: Dim los1 as New List(Of String) los1.Add(Some value) Dim los2
Let's say I have a DataTable: DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn(Country, typeof(string)));
Users on my site can add nodes of a custom type (let's call it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.